-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
45 lines (43 loc) · 1.19 KB
/
index.js
File metadata and controls
45 lines (43 loc) · 1.19 KB
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
const { ApolloServer } = require("apollo-server");
const mongoose = require("mongoose");
const schema = require("./modules");
const checkAuth = require("./utils/check-auth");
const { MONGODB, PORT } = require("./config/constants");
const server = new ApolloServer({
schema,
context: ({ req }) => ({ req }),
introspection: true,
playground: true,
subscriptions: {
onConnect: (connectionParams, webSocket, context) => {
console.log("on connect", connectionParams.authorization);
if (connectionParams.authorization) {
const user = checkAuth(
context,
connectionParams.authorization,
(sub = true)
);
return user;
}
throw new Error("Missing auth token!");
},
onDisconnect: (webSocket, context) => {
console.log(
new Date().toLocaleTimeString("de-DE"),
"subscriptions:onDisconnect"
);
},
},
});
mongoose
.connect(MONGODB, {
useNewUrlParser: true,
useCreateIndex: true,
useUnifiedTopology: true,
})
.then(() => {
console.log("Mongo DB connected");
return server.listen({ port: PORT }).then((res) => {
console.log(`Server running at ${res.url}`);
})
})