diff --git a/src/routes/meta.js b/src/routes/meta.js index 5a90a6c537..cfe258022a 100644 --- a/src/routes/meta.js +++ b/src/routes/meta.js @@ -26,6 +26,24 @@ function sendStylesheet(req, res, next) { res.type('text/css').send(200, meta.css.cache); } +function setupPluginSourceMapping(app) { + /* + These mappings are utilised by the source map file, as client-side + scripts defined in `scripts` in plugin.json are not normally + served to the end-user. These mappings are only accessible via + development mode (`./nodebb dev`) + */ + var routes = plugins.clientScripts, + mapping; + + routes.forEach(function(route) { + mapping = '/' + route.split('/').slice(7).join('/'); + app.get(mapping, function(req, res) { + res.type('text/javascript').sendfile(route); + }); + }); +} + module.exports = function(app, middleware, controllers) { app.get('/stylesheet.css', sendStylesheet); app.get('/nodebb.min.js', sendMinifiedJS); @@ -34,5 +52,6 @@ module.exports = function(app, middleware, controllers) { if (!minificationEnabled) { app.get('/nodebb.min.js.map', sendSourceMap); + setupPluginSourceMapping(app); } };