mirror of
https://github.com/strapi/strapi.git
synced 2025-09-26 17:00:55 +00:00
Mount static for each plugins
This commit is contained in:
parent
f4a1a2cec3
commit
f1d4a0bb86
@ -105,7 +105,7 @@ module.exports = strapi => {
|
|||||||
|
|
||||||
// Parse each route from the user config, load policies if any
|
// Parse each route from the user config, load policies if any
|
||||||
// and match the controller and action to the desired endpoint.
|
// 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 {
|
try {
|
||||||
const { route, policies, action } = routerChecker(value, endpoint);
|
const { route, policies, action } = routerChecker(value, endpoint);
|
||||||
|
|
||||||
@ -116,7 +116,7 @@ module.exports = strapi => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Parse each plugin's routes.
|
// Parse each plugin's routes.
|
||||||
_.forEach(strapi.config.routes.plugins, (value, plugin) => {
|
_.forEach(strapi.config.plugins.routes, (value, plugin) => {
|
||||||
try {
|
try {
|
||||||
// Create router for each plugin.
|
// Create router for each plugin.
|
||||||
// Prefix router with the plugin's name.
|
// Prefix router with the plugin's name.
|
||||||
|
@ -7,6 +7,9 @@
|
|||||||
// Node.js core.
|
// Node.js core.
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
|
// Public modules
|
||||||
|
const koa = require('koa');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Public assets hook
|
* Public assets hook
|
||||||
*/
|
*/
|
||||||
@ -28,9 +31,23 @@ module.exports = strapi => {
|
|||||||
|
|
||||||
initialize: cb => {
|
initialize: cb => {
|
||||||
if (strapi.config.static === true) {
|
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();
|
cb();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -136,7 +136,7 @@ module.exports = strapi => {
|
|||||||
strapi.plugins[plugin.name] = _.omitBy(_.get(strapi.plugins, plugin.name), _.isEmpty);
|
strapi.plugins[plugin.name] = _.omitBy(_.get(strapi.plugins, plugin.name), _.isEmpty);
|
||||||
|
|
||||||
// Merge API routes with the main ones.
|
// 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
|
// If the module doesn't have a definition at all
|
||||||
// just remove it completely from the dictionary.
|
// just remove it completely from the dictionary.
|
||||||
|
@ -54,6 +54,7 @@
|
|||||||
"koa-load-middlewares": "~1.0.0",
|
"koa-load-middlewares": "~1.0.0",
|
||||||
"koa-locale": "~1.2.0",
|
"koa-locale": "~1.2.0",
|
||||||
"koa-lusca": "~2.2.0",
|
"koa-lusca": "~2.2.0",
|
||||||
|
"koa-mount": "^1.3.0",
|
||||||
"koa-proxy": "~0.6.0",
|
"koa-proxy": "~0.6.0",
|
||||||
"koa-response-time": "~1.0.2",
|
"koa-response-time": "~1.0.2",
|
||||||
"koa-router": "~5.4.0",
|
"koa-router": "~5.4.0",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user