-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
27 lines (22 loc) · 691 Bytes
/
Copy pathserver.js
File metadata and controls
27 lines (22 loc) · 691 Bytes
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
import * as fs from "node:fs";
import express from "express";
const app = express();
app.use(express.text());
app.use(express.json());
app.use(
express.urlencoded({
extended: true,
}),
);
const portFlagIndex = process.argv.findIndex((item) => item === "--port");
const port = portFlagIndex !== -1 ? process.argv[portFlagIndex + 1] : 3000;
app.use(express.static("public", { extensions: ["html"] }));
const files = fs.readdirSync("api");
for (const file of files) {
const { default: route } = await import(`./api/${file}`);
const level = file.split(".")[0];
app.use(`/api/${level}`, route);
}
app.listen(port, () => {
console.log(`Server listening on port ${port}`);
});