-
Notifications
You must be signed in to change notification settings - Fork 53
/
server.ts
38 lines (31 loc) · 1.01 KB
/
server.ts
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
34
35
36
37
38
import express from "express";
import rateLimit from "express-rate-limit";
import next from "next";
import path from "path";
const dev = process.env.NODE_ENV !== "production";
const app = next({ dev });
const handle = app.getRequestHandler();
// Enable rate limiting
const limiter = rateLimit({
windowMs: 15 * 60 * 1000, // 15 minutes
max: 100, // limit each IP to 100 requests per windowMs
});
app.prepare().then(() => {
const server = express();
// Apply rate limiting to the /app route
server.use("/app", limiter);
// Serve index.html when someone navigates to /app
server.get("/app", (req, res) => {
res.sendFile(path.join(__dirname, "public/app/index.html"));
});
// Serve other static files under /app
server.use("/app", express.static(path.join(__dirname, "public/app")));
// Handle Next.js routes
server.all("*", (req, res) => {
return handle(req, res);
});
server.listen(3000, (err?: any) => {
if (err) throw err;
console.log("> Ready on http://localhost:3000");
});
});