-
Notifications
You must be signed in to change notification settings - Fork 13
/
server.js
45 lines (35 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
const express = require("express");
const next = require("next");
const port = parseInt(process.env.PORT, 10) || 3000;
const dev = process.env.NODE_ENV !== "production";
const app = next({ dev });
const handle = app.getRequestHandler();
//Configuration requires
const ConfigurationModel = require("./models/inputs.json");
const ConfigurationService = require("./services/ConfigurationService");
const ConfigurationController = require("./controllers/ConfigurationController");
//Configuration instances
const ConfigurationServiceInstance = new ConfigurationService(
ConfigurationModel
);
const ConfigurationControllerInstance = new ConfigurationController(
ConfigurationServiceInstance
);
app.prepare().then(() => {
const server = express();
//get configuration by path
server.get("/configuration/:path", (req, res) =>
ConfigurationControllerInstance.get(req, res)
);
server.post("/:path", (req, res) => {
console.log(req.body);
return res.sendStatus(200);
});
server.all("*", (req, res) => {
return handle(req, res);
});
server.listen(port, (err) => {
if (err) throw err;
console.log(`> Ready on http://localhost:${port}`);
});
});