소스 검색

fix HackHD integration when behind reverse proxy.

Koki Oyatsu 7 년 전
부모
커밋
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');
 const ApiResponse = require('../util/apiResponse');
 
 
 module.exports = function(crowi, app) {
 module.exports = function(crowi, app) {
+  const config = crowi.getConfig();
   const Page = crowi.models.Page;
   const Page = crowi.models.Page;
 
 
   // load GROWI agent script for HackMD
   // load GROWI agent script for HackMD
@@ -33,7 +34,13 @@ module.exports = function(crowi, app) {
       agentScriptContentTpl = swig.compileFile(agentScriptPath);
       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
     // generate definitions to replace
     const definitions = {
     const definitions = {