MCPcopy Create free account
hub / github.com/Lakr233/AssppWeb / httpsRedirect

Function httpsRedirect

backend/src/middleware/httpsRedirect.ts:4–13  ·  view source on GitHub ↗
(req: Request, res: Response, next: NextFunction)

Source from the content-addressed store, hash-verified

2import { config } from "../config.js";
3
4export function httpsRedirect(req: Request, res: Response, next: NextFunction) {
5 if (config.disableHttpsRedirect) return next();
6 if (req.headers["x-forwarded-proto"] === "http") {
7 // Only use the Host header (not x-forwarded-host) to prevent open redirects
8 const host = (req.headers["host"] || "").replace(/[^\w.\-:]/g, "");
9 if (!host) return next();
10 return res.redirect(301, `https://${host}${req.url}`);
11 }
12 next();
13}

Callers 1

middleware.test.tsFile · 0.85

Calls 1

nextFunction · 0.85

Tested by

no test coverage detected