mirror of
https://github.com/strapi/strapi.git
synced 2025-11-03 03:17:11 +00:00
Defer pulibc and uplaod middlewares
Signed-off-by: Alexandre Bodin <bodin.alex@gmail.com>
This commit is contained in:
parent
5a259ddf41
commit
b3a6114328
@ -22,6 +22,6 @@ module.exports = strapi => ({
|
|||||||
strapi.app.onerror(err);
|
strapi.app.onerror(err);
|
||||||
});
|
});
|
||||||
|
|
||||||
strapi.router.get('/uploads/(.*)', range, koaStatic(staticDir));
|
strapi.router.get('/uploads/(.*)', range, koaStatic(staticDir, { defer: true }));
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@ -27,21 +27,14 @@ module.exports = strapi => {
|
|||||||
const { defaultIndex, maxAge, path: publicPath } = strapi.config.middleware.settings.public;
|
const { defaultIndex, maxAge, path: publicPath } = strapi.config.middleware.settings.public;
|
||||||
const staticDir = path.resolve(strapi.dir, publicPath || strapi.config.paths.static);
|
const staticDir = path.resolve(strapi.dir, publicPath || strapi.config.paths.static);
|
||||||
|
|
||||||
// Match every route with an extension.
|
|
||||||
// The file without extension will not be served.
|
|
||||||
// Note: This route can be overriden by the user.
|
|
||||||
strapi.router.get(
|
|
||||||
'/(.*)',
|
|
||||||
koaStatic(staticDir, {
|
|
||||||
maxage: maxAge,
|
|
||||||
defer: false,
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
if (defaultIndex === true) {
|
if (defaultIndex === true) {
|
||||||
const index = fs.readFileSync(path.join(__dirname, 'index.html'), 'utf8');
|
const index = fs.readFileSync(path.join(__dirname, 'index.html'), 'utf8');
|
||||||
|
|
||||||
const serveIndexPage = async ctx => {
|
const serveIndexPage = async (ctx, next) => {
|
||||||
|
// defer rendering of strapi index page
|
||||||
|
await next();
|
||||||
|
if (ctx.body != null || ctx.status !== 404) return;
|
||||||
|
|
||||||
ctx.url = 'index.html';
|
ctx.url = 'index.html';
|
||||||
const isInitialised = await utils.isInitialised(strapi);
|
const isInitialised = await utils.isInitialised(strapi);
|
||||||
const data = {
|
const data = {
|
||||||
@ -70,6 +63,15 @@ module.exports = strapi => {
|
|||||||
strapi.router.get('/index.html', serveIndexPage);
|
strapi.router.get('/index.html', serveIndexPage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// serve files in public folder unless a sub router renders something else
|
||||||
|
strapi.router.get(
|
||||||
|
'/(.*)',
|
||||||
|
koaStatic(staticDir, {
|
||||||
|
maxage: maxAge,
|
||||||
|
defer: true,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
if (!strapi.config.serveAdminPanel) return;
|
if (!strapi.config.serveAdminPanel) return;
|
||||||
|
|
||||||
const basename = _.get(strapi.config.currentEnvironment.server, 'admin.path')
|
const basename = _.get(strapi.config.currentEnvironment.server, 'admin.path')
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user