mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 07:50:31 +00:00
Add environment variables to control settings
This commit is contained in:
22
src/index.ts
22
src/index.ts
@@ -6,8 +6,13 @@ import { InterchangeSystem, InterchangeSystemBuilderArguments } from "./entities
|
||||
import { ChapmanApiBasedParkingRepositoryLoader } from "./loaders/parking/ChapmanApiBasedParkingRepositoryLoader";
|
||||
import express from "express";
|
||||
import { expressMiddleware } from "@as-integrations/express5";
|
||||
import { RATE_LIMITS_DISABLED } from "./environment";
|
||||
import rateLimit from "express-rate-limit";
|
||||
import {
|
||||
RATE_LIMIT_DELAY_AFTER_REQUESTS,
|
||||
RATE_LIMIT_DELAY_MULTIPLIER_MS,
|
||||
RATE_LIMIT_WINDOW_MS,
|
||||
RATE_LIMITS_DISABLED
|
||||
} from "./environment";
|
||||
import slowDown from "express-slow-down";
|
||||
|
||||
const typeDefs = readFileSync("./schema.graphqls", "utf8");
|
||||
|
||||
@@ -60,12 +65,12 @@ async function main() {
|
||||
expressMiddleware(server, options)
|
||||
);
|
||||
} else {
|
||||
const limiter = rateLimit({
|
||||
windowMs: 60 * 1000, // Every minute
|
||||
limit: 20000,
|
||||
standardHeaders: 'draft-8', // draft-6: `RateLimit-*` headers; draft-7 & draft-8: combined `RateLimit` header
|
||||
legacyHeaders: false, // Disable the `X-RateLimit-*` headers.
|
||||
ipv6Subnet: 60, // Set to 60 or 64 to be less aggressive, or 52 or 48 to be more aggressive
|
||||
const limiter = slowDown({
|
||||
windowMs: RATE_LIMIT_WINDOW_MS,
|
||||
delayAfter: RATE_LIMIT_DELAY_AFTER_REQUESTS,
|
||||
delayMs: (hits) => {
|
||||
return hits * RATE_LIMIT_DELAY_MULTIPLIER_MS;
|
||||
}
|
||||
});
|
||||
app.use(
|
||||
"/",
|
||||
@@ -75,7 +80,6 @@ async function main() {
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
const port = process.env.PORT ? parseInt(process.env.PORT) : 4000;
|
||||
app.listen(port, () => {
|
||||
console.log(`Server ready at port ${port}`);
|
||||
|
||||
Reference in New Issue
Block a user