-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
30 lines (23 loc) · 854 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
import express from "express";
import bodyParser from "body-parser";
import userRouter from "./router/user.router.js";
import { valideMiddleware } from "./middleware/cors.js";
import path from "path";
import { fileURLToPath } from "url";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const app = express();
app.use(express.static("static"));
app.use(bodyParser.json());
app.use(express.urlencoded({ extended: true }));
app.use(valideMiddleware());
const staticPath = path.join(__dirname, "static");
app.use(express.static(staticPath));
app.use("/api", userRouter);
app.get("/", (req, res) => {
res.sendFile(path.join(__dirname, "static", "index.html"));
});
const PORT = process.env.PORT || 4000;
app.listen(PORT, () => {
console.log(`server is running on port http://localhost:${PORT}`);
});