forked from JarrodMFlesch/Our-Wedding-Website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
43 lines (32 loc) · 962 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
39
40
41
42
43
require('isomorphic-fetch');
require('dotenv');
const nextRoutes = require('next-routes');
const routes = nextRoutes();
const express = require('express');
const next = require('next');
const bodyParser = require('body-parser');
const unsupportedBrowser = require('./unsupported-browser');
const dev = process.env.NODE_ENV !== 'production';
const app = next({ dev });
const handle = routes.getRequestHandler(app);
const { PORT } = process.env;
app
.prepare()
.then(() => {
const server = express();
const port = PORT || 3000;
server.use(bodyParser.json());
server.use(bodyParser.urlencoded({ extended: false }));
server.use(unsupportedBrowser);
server.get('*', (req, res) => {
return handle(req, res);
});
server.listen(port, (err) => {
if (err) throw err;
console.log(`> Ready on http://localhost:${port}`);
});
})
.catch((ex) => {
console.error(ex.stack);
process.exit(1);
});