Shun Miyazawa %!s(int64=3) %!d(string=hai) anos
pai
achega
e501d7ed27
Modificáronse 1 ficheiros con 10 adicións e 9 borrados
  1. 10 9
      packages/app/src/server/crowi/express-init.js

+ 10 - 9
packages/app/src/server/crowi/express-init.js

@@ -67,22 +67,23 @@ module.exports = function(crowi, app) {
   const trustProxyCsv = configManager.getConfig('crowi', 'security:trustProxyCsv');
   const trustProxyHops = configManager.getConfig('crowi', 'security:trustProxyHops');
 
-  const trustProxies = [trustProxyBool, trustProxyCsv, trustProxyHops];
+  const isNotSpec = [trustProxyBool, trustProxyCsv, trustProxyHops].filter(trustProxy => trustProxy != null).length !== 1;
 
-  const isNotSpec = trustProxies.filter(trustProxy => trustProxy != null).length !== 1;
-
-  for (const trustProxy of trustProxies) {
+  try {
+    const trustProxy = trustProxyBool ?? trustProxyCsv ?? trustProxyHops;
     if (trustProxy != null) {
       app.set('trust proxy', trustProxy);
-      break;
+    }
+    if (isNotSpec) {
+      // eslint-disable-next-line max-len
+      logger.warn(`If multiple environment variables TRUST_PROXY_ ~ are set, they are set preferentially in the order of BOOL → CSV → HOPS. Set value: ${app.get('trust proxy')}`);
     }
   }
-
-  if (isNotSpec) {
-    // eslint-disable-next-line max-len
-    logger.warn(`If multiple environment variables TRUST_PROXY_ ~ are set, they are set preferentially in the order of BOOL → CSV → HOPS. Set value: ${app.get('trust proxy')}`);
+  catch (err) {
+    logger.error(err);
   }
 
+
   app.use(helmet({
     contentSecurityPolicy: false,
     expectCt: false,