Mount static for each plugins

This commit is contained in:
Aurélien Georget 2016-09-02 11:42:43 +02:00
parent f4a1a2cec3
commit f1d4a0bb86
4 changed files with 22 additions and 4 deletions

View File

@ -105,7 +105,7 @@ module.exports = strapi => {
// Parse each route from the user config, load policies if any
// and match the controller and action to the desired endpoint.
_.forEach(_.omit(strapi.config.routes, 'plugins'), (value, endpoint) => {
_.forEach(strapi.config.routes, (value, endpoint) => {
try {
const { route, policies, action } = routerChecker(value, endpoint);
@ -116,7 +116,7 @@ module.exports = strapi => {
});
// Parse each plugin's routes.
_.forEach(strapi.config.routes.plugins, (value, plugin) => {
_.forEach(strapi.config.plugins.routes, (value, plugin) => {
try {
// Create router for each plugin.
// Prefix router with the plugin's name.

View File

@ -7,6 +7,9 @@
// Node.js core.
const path = require('path');
// Public modules
const koa = require('koa');
/**
* Public assets hook
*/
@ -28,9 +31,23 @@ module.exports = strapi => {
initialize: cb => {
if (strapi.config.static === true) {
strapi.app.use(strapi.middlewares.static(path.resolve(strapi.config.appPath, strapi.config.paths.static)));
strapi.app.use(strapi.middlewares.static(path.resolve(strapi.config.appPath, strapi.config.paths.static), {
gzip: true
}));
}
// Mount static to a specific path (pattern: `/plugins/xXx`)
_.forEach(strapi.plugins, (value, plugin) => {
// Create koa sub-app
const app = koa();
app.use(strapi.middlewares.static(path.resolve(strapi.config.appPath, 'plugins', plugin, strapi.config.paths.static), {
gzip: true
}));
strapi.app.use(strapi.middlewares.mount(path.join('/plugins', plugin), app));
});
cb();
}
};

View File

@ -136,7 +136,7 @@ module.exports = strapi => {
strapi.plugins[plugin.name] = _.omitBy(_.get(strapi.plugins, plugin.name), _.isEmpty);
// Merge API routes with the main ones.
_.set(strapi.config.routes, 'plugins.' + plugin.name, _.get(strapi.plugins, plugin.name + '.config.routes'));
_.set(strapi.config, 'plugins.routes.' + plugin.name, _.get(strapi.plugins, plugin.name + '.config.routes'));
// If the module doesn't have a definition at all
// just remove it completely from the dictionary.

View File

@ -54,6 +54,7 @@
"koa-load-middlewares": "~1.0.0",
"koa-locale": "~1.2.0",
"koa-lusca": "~2.2.0",
"koa-mount": "^1.3.0",
"koa-proxy": "~0.6.0",
"koa-response-time": "~1.0.2",
"koa-router": "~5.4.0",