mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-11-12 07:01:31 +08:00
* Add new rate limiting flow * Oops * Fix nit * Fix some bugs * Split key generation functions * Remove 429 * Change message for root limiter * Flag 429 and add config * Add status code config * Check enabled flag * Add custom status for ape keys * Bump coverage * swapped conditions around whats the point of checking if the status code is in the array if the whole thing is turned off anyway Co-authored-by: Miodec <bartnikjack@gmail.com>
34 lines
758 B
TypeScript
34 lines
758 B
TypeScript
import cors from "cors";
|
|
import helmet from "helmet";
|
|
import addApiRoutes from "./api/routes";
|
|
import express, { urlencoded, json } from "express";
|
|
import contextMiddleware from "./middlewares/context";
|
|
import errorHandlingMiddleware from "./middlewares/error";
|
|
import {
|
|
badAuthRateLimiterHandler,
|
|
rootRateLimiter,
|
|
} from "./middlewares/rate-limit";
|
|
|
|
function buildApp(): express.Application {
|
|
const app = express();
|
|
|
|
app.use(urlencoded({ extended: true }));
|
|
app.use(json());
|
|
app.use(cors());
|
|
app.use(helmet());
|
|
|
|
app.set("trust proxy", 1);
|
|
|
|
app.use(contextMiddleware);
|
|
|
|
app.use(badAuthRateLimiterHandler);
|
|
app.use(rootRateLimiter);
|
|
|
|
addApiRoutes(app);
|
|
|
|
app.use(errorHandlingMiddleware);
|
|
|
|
return app;
|
|
}
|
|
|
|
export default buildApp();
|