Add environment variables to control settings

This commit is contained in:
2025-08-26 17:05:19 -07:00
parent 2c3d0a9fd4
commit 07ccd05734
4 changed files with 34 additions and 10 deletions

View File

@@ -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}`);