-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
40 lines (31 loc) · 1 KB
/
app.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
require("./init/env.init");
require("./init/mongoodb.init");
require("./init/adminAccount.init");
require("./init/redis.init");
const express = require("express");
const app = express();
const debug = require("debug")("app:server");
const path = require("path");
const cors = require("cors");
const environment = process.env.ENV;
// Enable cors ONLY FOR DEV
if (environment === "DEV") {
debug("CORS is enabled for development.");
app.use(cors());
} else {
debug("CORS is disabled.");
}
const host = process.env.HOST;
const port = process.env.PORT;
// serve vue app
app.use(express.static(path.join(__dirname, "/dist")));
app.get("/", (req, res) => {
debug("FILE PATH ", path.join(__dirname, "/dist/index.html"));
res.sendFile(path.join(__dirname, "/dist/index.html"));
});
require("./init/app.init")(app);
require("./init/routes.init")(app);
require("./middlewares/error.middleware")(app);
app.listen(process.env.PORT, process.env.HOST, () => {
debug(`Server is running at http://${host}:${port}/`);
});