-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
38 lines (30 loc) · 978 Bytes
/
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
const express = require('express');
const bodyParser = require('body-parser');
const session = require('express-session');
const path = require('path');
const dev = process.env.NODE_ENV !== 'production';
const next = require('next');
const pathMatch = require('path-match');
const app = next({ dev });
const handle = app.getRequestHandler();
const { parse } = require('url');
const apiRoutes = require('./server/routes/apiRoutes.js');
app.prepare().then(() => {
const server = express();
server.use('/api', apiRoutes);
server.get('/graph', (req, res) => {
return app.render(req, res, '/graph');
});
server.get('/world', (req, res) => {
return app.render(req, res, '/world');
});
server.get('*', (req, res) => {
return handle(req, res);
});
const PORT = process.env.PORT || 3000;
/* eslint-disable no-console */
server.listen(PORT, (err) => {
if (err) throw err;
console.log(`Server ready on http://localhost:${PORT}`);
});
});