Serve plugin static files

pull/528/head
Egil Moeller 2012-02-25 19:43:00 +01:00
parent 1d86c828bc
commit e542199aab
1 changed files with 14 additions and 2 deletions

View File

@ -1,5 +1,6 @@
var path = require('path'); var path = require('path');
var minify = require('../../utils/Minify'); var minify = require('../../utils/Minify');
var plugins = require("../../pluginfw/plugins");
exports.expressCreateServer = function (hook_name, args, cb) { exports.expressCreateServer = function (hook_name, args, cb) {
//serve static files //serve static files
@ -8,8 +9,19 @@ exports.expressCreateServer = function (hook_name, args, cb) {
res.write(minify.requireDefinition()); res.write(minify.requireDefinition());
res.end(); res.end();
}); });
args.app.get('/static/*', function(req, res)
{ args.app.get('/static/plugins/*', function(req, res) {
var url = req.url.replace(/\.\./g, '').split("?")[0];
url = url.split("/");
url.splice(0, 3);
var plugin_name = url.splice(0, 1)[0];
url = url.join("/");
var filePath = path.normalize(path.join(plugins.plugins[plugin_name].package.path, "static", url));
res.sendfile(filePath, { maxAge: exports.maxAge });
});
args.app.get('/static/*', function(req, res) {
var filePath = path.normalize(__dirname + "/../../.." + var filePath = path.normalize(__dirname + "/../../.." +
req.url.replace(/\.\./g, '').split("?")[0]); req.url.replace(/\.\./g, '').split("?")[0]);
res.sendfile(filePath, { maxAge: exports.maxAge }); res.sendfile(filePath, { maxAge: exports.maxAge });