Просмотр исходного кода

fix HackHD integration when behind reverse proxy.

Koki Oyatsu 7 лет назад
Родитель
Сommit
f62a57ad84
1 измененных файлов с 8 добавлено и 1 удалено
  1. 8 1
      lib/routes/hackmd.js

+ 8 - 1
lib/routes/hackmd.js

@@ -7,6 +7,7 @@ const axios = require('axios');
 const ApiResponse = require('../util/apiResponse');
 
 module.exports = function(crowi, app) {
+  const config = crowi.getConfig();
   const Page = crowi.models.Page;
 
   // load GROWI agent script for HackMD
@@ -33,7 +34,13 @@ module.exports = function(crowi, app) {
       agentScriptContentTpl = swig.compileFile(agentScriptPath);
     }
 
-    const origin = `${req.protocol}://${req.get('host')}`;
+    var origin = `${req.protocol}://${req.get('host')}`;
+
+    // use config.crowi['app:url'] when exist req.headers['x-forwarded-proto'].
+    // refs: lib/crowi/express-init.js
+    if (config.crowi && config.crowi['app:url']) {
+      origin = config.crowi['app:url'];
+    }
 
     // generate definitions to replace
     const definitions = {