You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
nodebb/src/routes/plugins.js

31 lines
805 B
JavaScript

"use strict";
9 years ago
var _ = require('underscore');
var path = require('path');
var plugins = require('../plugins');
module.exports = function(app, middleware, controllers) {
// Static Assets
10 years ago
app.get('/plugins/:id/*', middleware.addExpiresHeaders, function(req, res, next) {
9 years ago
var relPath = req._parsedUrl.pathname.replace('/plugins/', '');
var matches = _.map(plugins.staticDirs, function(realPath, mappedPath) {
if (relPath.match(mappedPath)) {
var pathToFile = path.join(plugins.staticDirs[mappedPath], decodeURIComponent(relPath.slice(mappedPath.length)));
if (pathToFile.startsWith(plugins.staticDirs[mappedPath])) {
return pathToFile;
}
}
return null;
}).filter(Boolean);
if (!matches || !matches.length) {
10 years ago
return next();
}
res.sendFile(matches[0]);
});
};