-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
46 lines (37 loc) · 1.11 KB
/
index.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
require("source-map-support").install();
const express = require("express");
const http = require("http");
const { parse } = require("url");
// const { createConnection } = require("typeorm");
const backend = require("./server");
const nextApp = require("billing-next");
const app = express();
// const ormConfig = require("./ormconfig");
(async () => {
const mod = await backend({ dev: true });
const nextHandler = await nextApp({ dev: true });
// await createConnection(ormConfig["default"]);
app.use(`/api/v1`, (req, res) => {
mod()
.then((a) => {
const { apiRouter } = a.httpRoutes();
apiRouter(req, res);
})
.catch((err) => {
console.log(err);
res.status(500).send("oops... internal server error");
});
});
app.use((req, res) => {
const parsedUrl = parse(req.url, true);
nextHandler(req, res, parsedUrl);
});
const httpServer = http.createServer(app);
const port = 3001;
httpServer.listen(port, () => {
console.log(`server ready on port http://0.0.0.0:${port}`);
});
})().catch((err) => {
console.log(err);
process.exit(0);
});