hackmd.js 716 B

12345678910111213141516171819202122232425
  1. module.exports = function(crowi, app) {
  2. const path = require('path');
  3. const fs = require('graceful-fs');
  4. // load GROWI agent script for HackMD
  5. const manifest = require(path.join(crowi.publicDir, 'manifest.json'));
  6. const agentScriptPath = path.join(crowi.publicDir, manifest['js/agent-for-hackmd.js']);
  7. const agentScriptContent = fs.readFileSync(agentScriptPath, 'utf8').toString();
  8. /**
  9. * loadAgent action
  10. * This should be access from HackMD and send agent script
  11. *
  12. * @param {object} req
  13. * @param {object} res
  14. */
  15. const loadAgent = function(req, res) {
  16. res.set('Content-Type', 'application/javascript');
  17. res.send(agentScriptContent);
  18. };
  19. return {
  20. loadAgent,
  21. };
  22. };