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

delay compiling 'agentScriptContentTpl' for HackMD

Yuki Takei 7 лет назад
Родитель
Сommit
92f27e535a
1 измененных файлов с 6 добавлено и 1 удалено
  1. 6 1
      lib/routes/hackmd.js

+ 6 - 1
lib/routes/hackmd.js

@@ -12,7 +12,7 @@ module.exports = function(crowi, app) {
   const manifest = require(path.join(crowi.publicDir, 'manifest.json'));
   const agentScriptPath = path.join(crowi.publicDir, manifest['js/agent-for-hackmd.js']);
   // generate swig template
-  const agentScriptContentTpl = swig.compileFile(agentScriptPath);
+  let agentScriptContentTpl = undefined;
 
 
   /**
@@ -23,6 +23,11 @@ module.exports = function(crowi, app) {
    * @param {object} res
    */
   const loadAgent = function(req, res) {
+    // generate swig template
+    if (agentScriptContentTpl == null) {
+      agentScriptContentTpl = swig.compileFile(agentScriptPath);
+    }
+
     const origin = `${req.protocol}://${req.get('host')}`;
     const styleFilePath = origin + manifest['styles/style-hackmd.css'];