-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathserver.js
77 lines (63 loc) · 1.49 KB
/
server.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import express from "express";
import path from "path";
import bodyParser from "body-parser";
import session from "express-session";
import memoryStore from "memorystore";
import { graphqlExpress, graphiqlExpress } from "graphql-server-express";
import { execute, subscribe } from "graphql";
import { createServer } from "http";
import { SubscriptionServer } from "subscriptions-transport-ws";
const app = express();
const PORT = process.env.PORT || 3000;
app.set("view engine", "ejs");
import { schema } from "./mat-che/schema.js";
const MemoryStore = memoryStore(session);
app.use(
session({
store: new MemoryStore({
checkPeriod: 300 //check for expired entries every 5 minutes
}),
secret: "not-so-secret",
resave: false,
saveUninitialized: true
})
);
app.get("/", (req, res) =>
res.render("index", {
google_tracking_id: process.env.GOOGLE_TRACKING_ID
})
);
app.get("/bundle.js", (req, res) =>
res.sendFile(path.join(__dirname + "/build/bundle.js"))
);
app.use(
"/graphql",
bodyParser.json(),
graphqlExpress(req => ({
schema: schema,
context: {
session: req.session
}
}))
);
app.use(
"/graphiql",
graphiqlExpress(req => ({
endpointURL: "/graphql",
subscriptionsEndpoint: `ws://${req.headers.host}/subscriptions`
}))
);
const ws = createServer(app);
ws.listen(PORT, () => {
new SubscriptionServer(
{
execute,
subscribe,
schema
},
{
server: ws,
path: "/subscriptions"
}
);
});