|
@@ -1,11 +1,13 @@
|
|
|
module.exports = function(crowi, app) {
|
|
module.exports = function(crowi, app) {
|
|
|
const path = require('path');
|
|
const path = require('path');
|
|
|
- const fs = require('graceful-fs');
|
|
|
|
|
|
|
+ const swig = require('swig-templates');
|
|
|
|
|
|
|
|
// load GROWI agent script for HackMD
|
|
// load GROWI agent script for HackMD
|
|
|
const manifest = require(path.join(crowi.publicDir, 'manifest.json'));
|
|
const manifest = require(path.join(crowi.publicDir, 'manifest.json'));
|
|
|
const agentScriptPath = path.join(crowi.publicDir, manifest['js/agent-for-hackmd.js']);
|
|
const agentScriptPath = path.join(crowi.publicDir, manifest['js/agent-for-hackmd.js']);
|
|
|
- const agentScriptContent = fs.readFileSync(agentScriptPath, 'utf8').toString();
|
|
|
|
|
|
|
+ // generate swig template
|
|
|
|
|
+ const agentScriptContentTpl = swig.compileFile(agentScriptPath);
|
|
|
|
|
+
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* loadAgent action
|
|
* loadAgent action
|
|
@@ -15,8 +17,16 @@ module.exports = function(crowi, app) {
|
|
|
* @param {object} res
|
|
* @param {object} res
|
|
|
*/
|
|
*/
|
|
|
const loadAgent = function(req, res) {
|
|
const loadAgent = function(req, res) {
|
|
|
|
|
+
|
|
|
|
|
+ // generate definitions to replace
|
|
|
|
|
+ const definitions = {
|
|
|
|
|
+ origin: `${req.protocol}://${req.get('host')}`
|
|
|
|
|
+ };
|
|
|
|
|
+ // inject
|
|
|
|
|
+ const script = agentScriptContentTpl(definitions);
|
|
|
|
|
+
|
|
|
res.set('Content-Type', 'application/javascript');
|
|
res.set('Content-Type', 'application/javascript');
|
|
|
- res.send(agentScriptContent);
|
|
|
|
|
|
|
+ res.send(script);
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
return {
|
|
return {
|