-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
54 lines (42 loc) · 1.74 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
const bodyParser = require('body-parser');
const cookieParser = require('cookie-parser');
const express = require('express');
const helmet = require('helmet');
const next = require('next');
const port = parseInt(process.env.PORT, 10) || 3000;
const dev = process.env.NODE_ENV !== 'production';
const app = next({ dev });
const handle = app.getRequestHandler();
app.prepare()
.then(() => {
const server = express();
server.use(helmet());
server.use(bodyParser.urlencoded({ extended: true }));
server.use(cookieParser());
server.use(bodyParser.json());
server.use(bodyParser.urlencoded({ extended: true }));
server.get('/favicon.ico', (req, res) => res.sendStatus(204));
server.get('/', (req, res) => handle(req, res));
server.get('/login', (req, res) => handle(req, res));
server.get('/:groupName', (req, res) => {
const actualPage = '/group';
const queryParams = { groupName: req.params.groupName };
return app.render(req, res, actualPage, queryParams);
});
server.get('/:groupName/events/:eventId', (req, res) => {
const actualPage = '/event';
const queryParams = { groupName: req.params.groupName, eventId: req.params.eventId };
return app.render(req, res, actualPage, queryParams);
});
server.get('/:groupName/events/:eventId/rsvps', (req, res) => {
const actualPage = '/rsvps';
const queryParams = { groupName: req.params.groupName, eventId: req.params.eventId };
return app.render(req, res, actualPage, queryParams);
});
server.get('*', (req, res) => handle(req, res));
server.listen(port, (err) => {
if (err) throw err;
console.log(`> Ready on port: ${port}`); // eslint-disable-line no-console
});
return server;
});