-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.js
46 lines (34 loc) · 1.16 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
require('dotenv').config();
const express = require('express');
const bodyParser = require('body-parser');
const cookieParser = require('cookie-parser');
const cors = require('cors');
const { parse } = require('url');
const dev = process.env.NODE_ENV !== 'production';
const nextJs = require('next')({ dev });
const checkAuth = require('./api/services/check_auth');
const mountEndpoints = require('./api/endpoints');
const app = express();
const nextJsHandler = nextJs.getRequestHandler();
console.log(process.env.DOMAIN_NAME);
//app.use(cors());
app.use(bodyParser.json());
app.use(cookieParser());
//app.use(bodyParser.urlencoded({extended: false}));
app.use((req, res, next)=> {
// req.parsedUrl.pathname, req.parsedUrl.query
req.parsedUrl = parse(req.url, true);
next();
})
// Verify jwt.
app.use('/api/*', checkAuth);
// Mount api endpoints.
mountEndpoints(app);
app.use('/shop', (req, res)=> {
nextJs.render(req, res, '/', req.parsedUrl.query);
});
app.use((req, res) => nextJsHandler(req, res, req.parsedUrl));
const PORT = process.env.PORT || 3000;
nextJs.prepare().then(() => {
app.listen(PORT, () => console.log(`> Ready on http://localhost:${PORT}`));
});