-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
44 lines (37 loc) · 1.34 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
const express = require('express');
const next = require('next');
const moment = require('moment');
const bodyParser = require('body-parser');
const { join } = require('path');
const { parse } = require('url');
const routes = require('./routes/index');
const dev = process.env.NODE_ENV !== 'production';
const app = next({ dev });
const handle = app.getRequestHandler();
const PORT = process.env.PORT || 3000;
app.prepare()
.then(() => {
const server = express();
server.use(bodyParser.json());
server.get('/sw.js', (req, res) => {
const parsedUrl = parse(req.url, true);
const { pathname } = parsedUrl;
const filePath = join(__dirname, 'build', pathname);
app.serveStatic(req, res, filePath);
});
server.post('/auth/signin', routes.auth.signIn);
server.post('/api/me/profile/list', routes.profile.list);
server.get('*', (req, res) => handle(req, res));
server.listen(PORT, (err) => {
if (err) {
throw err;
}
const apibaseurl = process.env.API_BASE_URL || process.env.NOW_URL;
console.log(`Using base url: '${apibaseurl}'`);
console.log(`> Ready on port ${PORT}`);
});
})
.catch((ex) => {
console.error(ex.stack);
process.exit(1);
});