forked from MustansirZia/next-express-bootstrap-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
next.js
26 lines (24 loc) · 728 Bytes
/
next.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
/* eslint-disable no-param-reassign */
const next = require('next');
const dev = process.env.NODE_ENV !== 'production';
const app = next({ dev, dir: './app' });
const handle = app.getRequestHandler();
module.exports = (async server => {
await app.prepare();
// Middleware to insert app and handle inside the req object.
server.use('/', (req, res, n) => {
req.app = app;
req.handle = handle;
n();
});
server.originalListen = server.listen;
server.listen = (port) => {
// If none of the custom routing handlers from express are hit,
// defer to next's own handler.
server.get('*', (req, res) => {
req.handle(req, res);
});
server.originalListen(port);
};
return server;
});