forked from fs/react-next-base
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
41 lines (34 loc) · 1.09 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
/* eslint-disable @typescript-eslint/no-var-requires */
const dotenv = require('dotenv');
dotenv.config();
const next = require('next');
const express = require('express');
const secure = require('express-force-https');
const bodyParser = require('body-parser');
const graphqlProxyMiddleware = require('./server/middlewares/graphql');
const routes = require('./routes');
const { DEV, PORT, GRAPHQL_APP_URL } = require('./config/vars');
// Create body-parser json middleware
const bodyParserJSON = bodyParser.json();
// Create the Express-Next App
const app = next({ dev: DEV });
const handle = routes.getRequestHandler(app);
// Start the app
app
.prepare()
// Start Express server and serve the
.then(() => {
express()
// use proxy middleware to send graphql requests to api server
.use(GRAPHQL_APP_URL, bodyParserJSON, graphqlProxyMiddleware)
.use(secure)
.use(handle)
.listen(PORT, (err) => {
if (err) throw err;
console.log(`> Ready on http://localhost:${PORT}`);
});
})
.catch((ex) => {
console.error(ex.stack);
process.exit(1);
});