fix HTTPS reuqirement when frontend URL is nto HTTPS

This commit is contained in:
Zimeng Xiong
2026-02-07 10:30:49 -08:00
parent 8161a563f0
commit 173c050f58
+6 -2
View File
@@ -259,8 +259,12 @@ app.use((req, res, next) => {
next();
});
// HTTPS enforcement in production
if (config.nodeEnv === "production") {
// HTTPS enforcement in production only when configured frontend origins use HTTPS.
const shouldEnforceHttps =
config.nodeEnv === "production" &&
allowedOrigins.some((origin) => origin.toLowerCase().startsWith("https://"));
if (shouldEnforceHttps) {
app.use((req, res, next) => {
if (req.header("x-forwarded-proto") !== "https") {
res.redirect(`https://${req.header("host")}${req.url}`);