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

42 lines
1004 B
JavaScript

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