-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.ts
27 lines (23 loc) · 797 Bytes
/
index.ts
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
import { Handler as ExpressHandler } from 'express';
import { join as pathJoin } from 'path';
import session from 'express-session';
import { createServer } from './backend/Server';
import { defaultPort, frontendPath } from './backend/Constants';
import { createSocket } from './backend/Socket';
const staticPath = pathJoin(__dirname, frontendPath);
const port = process.env.PORT || defaultPort;
const secret = process.env.NODE_ENV === 'production' ? process.env.COOKIE_SECRET || '' : 'DEV_COOKIE_SECRET';
const sessionMiddleware: ExpressHandler = session({
secret,
resave: false,
saveUninitialized: false,
cookie: {
maxAge: 2 * 60 * 60 * 1000 // 2 hours
}
});
const server = createServer({
port,
staticPath,
sessionMiddleware,
});
createSocket(server, sessionMiddleware);