Skip to content
Merged
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: 5 additions & 7 deletions backend/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ import { caseLawRouter } from "./routes/caseLaw";
export const app = express();
const isProduction = process.env.NODE_ENV === "production";

// Ceiling for JSON API requests. File uploads use multipart handling and
// are governed by separate upload limits.
const JSON_BODY_LIMIT = "50mb";

function envInt(name: string, fallback: number): number {
const raw = process.env[name];
if (!raw) return fallback;
Expand Down Expand Up @@ -84,10 +88,6 @@ const dataDeleteLimiter = makeLimiter({
message: "Too many data deletion requests. Please try again later.",
});

function jsonLimitForPath(path: string): string {
return "50mb";
}

app.disable("x-powered-by");
app.set("trust proxy", envInt("TRUST_PROXY_HOPS", 1));

Expand Down Expand Up @@ -142,9 +142,7 @@ app.delete("/user/chats", dataDeleteLimiter);
app.delete("/user/projects", dataDeleteLimiter);
app.delete("/user/tabular-reviews", dataDeleteLimiter);

app.use((req, res, next) =>
express.json({ limit: jsonLimitForPath(req.path) })(req, res, next),
);
app.use(express.json({ limit: JSON_BODY_LIMIT }));

app.use("/chat", chatRouter);
app.use("/projects", projectsRouter);
Expand Down
Loading