-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
32 lines (32 loc) · 969 Bytes
/
server.js
File metadata and controls
32 lines (32 loc) · 969 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
28
29
30
31
32
import express from "express";
import cors from "cors";
import fs from "fs";
import path from "path";
import { fileURLToPath } from "url";
import { apiRouter } from "./router/apiRouter.js";
import { rateLimit } from 'express-rate-limit';
const app = express();
const port = Number(process.env.PORT) || 3000;
const limiter = rateLimit({
windowMs: 10 * 60 * 1000, // 10 minutes
limit: 100,
standardHeaders: 'draft-8',
legacyHeaders: false,
ipv6Subnet: 56,
});
app.use(cors());
app.use(express.json());
app.use("/api", apiRouter);
app.use(limiter);
const __filename = fileURLToPath(import.meta.url);
const buildDir = path.join(path.dirname(__filename), 'dist');
if (fs.existsSync(buildDir)) {
app.use(express.static(buildDir));
}
app.use((req, res) => {
return res.sendFile(path.join(buildDir, 'index.html'));
});
app.listen(port, '0.0.0.0', () => {
console.log(`Server listening on port ${port}...`);
});
//# sourceMappingURL=server.js.map