-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.ts
32 lines (25 loc) · 757 Bytes
/
app.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
import compression from "compression";
import express, { static as expressStatic } from "express";
import { join } from "path";
const app = express();
// set up rate limiter: maximum of five requests per minute
const RateLimit = require("express-rate-limit");
const limiter = new RateLimit({
windowMs: 1 * 60 * 1000, // 1 minute
max: 5,
});
// apply rate limiter to all requests
app.use(limiter);
app.use(compression());
app.use(expressStatic(join(__dirname, "dist")));
app.get("/", (_req, res) => {
res.sendFile("index.html", {
root: join(__dirname, "dist"),
});
});
// Start the server
const PORT = process.env.PORT || 8080;
app.listen(PORT, () => {
console.log(`App listening on port ${PORT}`);
});
export default app;