fix HTTPS reuqirement when frontend URL is nto HTTPS
This commit is contained in:
@@ -259,8 +259,12 @@ app.use((req, res, next) => {
|
|||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
|
|
||||||
// HTTPS enforcement in production
|
// HTTPS enforcement in production only when configured frontend origins use HTTPS.
|
||||||
if (config.nodeEnv === "production") {
|
const shouldEnforceHttps =
|
||||||
|
config.nodeEnv === "production" &&
|
||||||
|
allowedOrigins.some((origin) => origin.toLowerCase().startsWith("https://"));
|
||||||
|
|
||||||
|
if (shouldEnforceHttps) {
|
||||||
app.use((req, res, next) => {
|
app.use((req, res, next) => {
|
||||||
if (req.header("x-forwarded-proto") !== "https") {
|
if (req.header("x-forwarded-proto") !== "https") {
|
||||||
res.redirect(`https://${req.header("host")}${req.url}`);
|
res.redirect(`https://${req.header("host")}${req.url}`);
|
||||||
|
|||||||
Reference in New Issue
Block a user