mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-03 04:25:55 +01:00
fixes #4576
This commit is contained in:
@@ -79,31 +79,36 @@ module.exports = function(Meta) {
|
|||||||
],
|
],
|
||||||
|
|
||||||
// modules listed below are routed through express (/src/modules) so they can be defined anonymously
|
// modules listed below are routed through express (/src/modules) so they can be defined anonymously
|
||||||
modules: [
|
modules: {
|
||||||
'./node_modules/chart.js/Chart.js',
|
"Chart.js": './node_modules/chart.js/Chart.js',
|
||||||
'./node_modules/mousetrap/mousetrap.js',
|
"mousetrap.js": './node_modules/mousetrap/mousetrap.js',
|
||||||
|
|
||||||
'public/vendor/buzz/buzz.js'
|
"buzz.js": 'public/vendor/buzz/buzz.js'
|
||||||
]
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Meta.js.bridgeModules = function(app, callback) {
|
Meta.js.bridgeModules = function(app, callback) {
|
||||||
// Add routes for AMD-type modules to serve those files
|
// Add routes for AMD-type modules to serve those files
|
||||||
var numBridged = 0;
|
var numBridged = 0,
|
||||||
|
addRoute = function(relPath) {
|
||||||
|
app.get('/src/modules/' + relPath, function(req, res) {
|
||||||
|
return res.sendFile(path.join(__dirname, '../../', Meta.js.scripts.modules[relPath]), {
|
||||||
|
maxAge: app.enabled('cache') ? 5184000000 : 0
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
async.series([
|
async.series([
|
||||||
function(next) {
|
function(next) {
|
||||||
async.each(Meta.js.scripts.modules, function(localPath, next) {
|
for(var relPath in Meta.js.scripts.modules) {
|
||||||
app.get('/src/modules/' + path.basename(localPath), function(req, res) {
|
if (Meta.js.scripts.modules.hasOwnProperty(relPath)) {
|
||||||
return res.sendFile(path.join(__dirname, '../../', localPath), {
|
addRoute(relPath);
|
||||||
maxAge: app.enabled('cache') ? 5184000000 : 0
|
++numBridged;
|
||||||
});
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
++numBridged;
|
next();
|
||||||
next();
|
|
||||||
}, next);
|
|
||||||
}
|
}
|
||||||
], function(err) {
|
], function(err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
|||||||
@@ -176,10 +176,19 @@ module.exports = function(Plugins) {
|
|||||||
winston.verbose('[plugins] Found ' + pluginData.modules.length + ' AMD-style module(s) for plugin ' + pluginData.id);
|
winston.verbose('[plugins] Found ' + pluginData.modules.length + ' AMD-style module(s) for plugin ' + pluginData.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
meta.js.scripts.modules = meta.js.scripts.modules.concat(pluginData.modules.map(function(file) {
|
var modules = {},
|
||||||
return path.join('./node_modules/', pluginData.id, file);
|
strip = pluginData.hasOwnProperty('modulesStrip') ? parseInt(pluginData.modulesStrip, 10) : 0;
|
||||||
}));
|
|
||||||
}
|
pluginData.modules.forEach(function(file) {
|
||||||
|
if (strip) {
|
||||||
|
modules[file.replace(new RegExp('\.?(\/[^\/]+){' + strip + '}\/'), '')] = path.join('./node_modules/', pluginData.id, file);
|
||||||
|
} else {
|
||||||
|
modules[path.basename(file)] = path.join('./node_modules/', pluginData.id, file);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
meta.js.scripts.modules = _.extend(meta.js.scripts.modules, modules);
|
||||||
|
} /* one could conceivably add an else..if here for plugins to pass modules in as an Object */
|
||||||
|
|
||||||
callback();
|
callback();
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user