-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
31 lines (25 loc) · 832 Bytes
/
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
require("dotenv").config();
const express = require("express");
const consola = require("consola");
const serveStatic = require("serve-static");
const path = require("path");
const app = express();
const apiController = require("./src/server/api/controller");
const port = 3000;
async function start() {
if (process.env.NODE_ENV === "development") {
app.use("/", serveStatic(path.join(__dirname, "./dist")));
// this * route is to serve project on different page routes except root `/`
app.get("/", (req, res) => {
res.sendFile(path.join(__dirname, "./dist/index.html"));
});
}
apiController(app);
// Listen the server
app.listen(port);
consola.ready({
message: `Server listening on http://localhost:${port}`,
badge: true,
});
}
start();