-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
33 lines (27 loc) · 895 Bytes
/
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
import express from "express";
import path, { dirname } from "path";
import { fileURLToPath } from "url";
import cors from "cors";
import ejs from "ejs";
import bodyParser from "body-parser";
import apiRoutes from "./routers/api.js";
const app = express();
const __dirname = dirname(fileURLToPath(import.meta.url));
app.use(cors());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.engine("html", ejs.renderFile);
app.set("view engine", "ejs");
app.set("views", path.join(__dirname, "/pages"));
app.use(express.static(path.join(__dirname, "/public")));
app.set("json spaces", 1);
app.get("/", (req, res) => {
res.render("index");
});
app.use("/api", apiRoutes); // Api routes
app.get("/*", (req, res) => {
res.status(404).render("404");
});
app.listen(8888, () => {
console.log("App is running on http://localhost:8888 --- https://vsldev.tk");
});