-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
26 lines (25 loc) · 806 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
import path from "path";
import { fileURLToPath } from "url";
import initDB from "./database/initDB.js";
import initRoutes from "./routes/initRoutes.js";
import express from "express";
import cors from "cors";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const PORT = process.env.PORT || 4000;
const app = express();
app.use(express.json({ extended: true }));
app.use(express.static(path.join(__dirname, "./l4n-task-client/build")));
app.use(cors());
initRoutes(app);
app.get("*", (req, res) => {
res.sendFile(path.join(__dirname + "/l4n-task-client/build/index.html"));
});
(async function initServer() {
try {
await initDB();
app.listen(PORT, () => console.log(`Running on port: ${PORT}`));
} catch (err) {
console.log(err);
}
})();