Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion backend/common.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import PinoHttp from 'pino-http';
import rateLimit from 'express-rate-limit';
import { handleDockerDesktopSubsitution } from './docker-desktop-substitution';
import { filters } from './request-filters';

Expand Down Expand Up @@ -142,9 +143,18 @@ export const makeHandleRequest = () => {
};
};

// Rate limiter: Max 100 requests per 1 minutes per IP
const limiter = rateLimit({
windowMs: 1 * 60 * 1000,
max: 100,
message: 'Too many requests from this IP, please try again later.',
standardHeaders: true,
legacyHeaders: false,
});

export const serveStaticApp = (app, requestPath, directoryPath) => {
app.use(requestPath, express.static(path.join(__dirname, directoryPath)));
app.get(requestPath + '*', (_, res) =>
app.get(requestPath + '*splat', limiter, (_, res) =>
res.sendFile(path.join(__dirname + directoryPath + '/index.html')),
);
};
Expand Down
Loading
Loading