monkeytype/backend/src/app.ts
Bruce Berrios 9da5e441be
Add new rate limiting flow (#3230) Bruception
* 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>
2022-06-28 13:45:57 +02:00

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();