From e542199aab53089921a41dcd0b9b98effe48f20b Mon Sep 17 00:00:00 2001 From: Egil Moeller Date: Sat, 25 Feb 2012 19:43:00 +0100 Subject: [PATCH] Serve plugin static files --- node/hooks/express/static.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/node/hooks/express/static.js b/node/hooks/express/static.js index 99f6eeff7..937fb26ec 100644 --- a/node/hooks/express/static.js +++ b/node/hooks/express/static.js @@ -1,5 +1,6 @@ var path = require('path'); var minify = require('../../utils/Minify'); +var plugins = require("../../pluginfw/plugins"); exports.expressCreateServer = function (hook_name, args, cb) { //serve static files @@ -8,8 +9,19 @@ exports.expressCreateServer = function (hook_name, args, cb) { res.write(minify.requireDefinition()); 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 + "/../../.." + req.url.replace(/\.\./g, '').split("?")[0]); res.sendfile(filePath, { maxAge: exports.maxAge });