-
Notifications
You must be signed in to change notification settings - Fork 0
/
nextjs-server.js
47 lines (38 loc) · 1.08 KB
/
nextjs-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
47
import express from 'express';
import next from 'next';
import 'regenerator-runtime/runtime';
import bodyParser from 'body-parser';
import routes from './routes';
import Auth from './api/Auth';
require('dotenv').config({ path: './.env' });
const port = parseInt(process.env.PORT, 10) || 3000;
const dev = process.env.NODE_ENV !== 'production';
const app = next({ dev });
const handler = routes.getRequestHandler(app);
app.prepare().then(() => {
const server = express();
server.use(bodyParser.json());
server.use(
bodyParser.urlencoded({
extended: true,
}),
);
server.use(express.static('public'));
server.post('/login', async (req, res) => {
const authAPI = new Auth();
const response = await authAPI
.login(req)
.then((result) => {
return result;
})
.catch((error) => {
return error;
});
res.end(JSON.stringify(response));
});
server.use(handler).listen(port, (err) => {
if (err) throw err;
/* eslint-disable-next-line no-console */
console.log(`> Ready on http://localhost:${port}`);
});
});