-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
47 lines (35 loc) · 1.09 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
const express = require("express");
const { createServer } = require("http");
const { VoyagerServer } = require("@aerogear/voyager-server");
const cors = require("cors");
const mongoose = require("mongoose");
const subscriptionServer = require("./subscriptions");
const { typeDefs, resolvers } = require("./src");
const { mongodbUrl } = require("./keys");
// Connecting Database
mongoose
.connect(mongodbUrl, { useNewUrlParser: true })
.then(() => console.log("DB connected!"))
.catch(() => console.log("DB connection failed!"));
mongoose.set("useCreateIndex", true);
const PORT = 4000;
let keycloakService = null;
const app = express();
app.use(cors());
const httpServer = createServer(app);
app.use(cors())
const apolloConfig = {
typeDefs,
resolvers
};
const voyagerConfig = {
securityService: keycloakService
};
const apolloServer = VoyagerServer(apolloConfig, voyagerConfig);
apolloServer.applyMiddleware({ app });
httpServer.listen({
port: PORT
}, () => {
console.log(`🚀 Server ready at http://localhost:${PORT}/graphql`)
subscriptionServer(keycloakService, httpServer, apolloServer)
});