mirror of
https://github.com/strapi/strapi.git
synced 2025-11-17 18:51:22 +00:00
fix: serve admin static file with public cache
This commit is contained in:
parent
adffc30bc7
commit
970f1d2b5d
@ -32,7 +32,7 @@ const registerAdminPanelRoute = ({ strapi }) => {
|
|||||||
path: `${strapi.config.admin.path}/:path*`,
|
path: `${strapi.config.admin.path}/:path*`,
|
||||||
handler: [
|
handler: [
|
||||||
serveAdminMiddleware,
|
serveAdminMiddleware,
|
||||||
serveStatic(buildDir, { maxage: 60000, defer: false, index: 'index.html' }),
|
serveStatic(buildDir, { maxage: 31536000, defer: false, index: 'index.html' }),
|
||||||
],
|
],
|
||||||
config: { auth: false },
|
config: { auth: false },
|
||||||
},
|
},
|
||||||
@ -46,6 +46,13 @@ const serveStatic = (filesDir, koaStaticOptions = {}) => {
|
|||||||
return async (ctx, next) => {
|
return async (ctx, next) => {
|
||||||
const prev = ctx.path;
|
const prev = ctx.path;
|
||||||
const newPath = path.basename(ctx.path);
|
const newPath = path.basename(ctx.path);
|
||||||
|
const ext = path.extname(ctx.path);
|
||||||
|
|
||||||
|
// publicly cache static files to avoid unnecessary network & disk access
|
||||||
|
if (ext === '.css' || ext === '.js') {
|
||||||
|
ctx.set('cache-control', 'public, max-age=31536000, immutable');
|
||||||
|
}
|
||||||
|
|
||||||
ctx.path = newPath;
|
ctx.path = newPath;
|
||||||
await serve(ctx, async () => {
|
await serve(ctx, async () => {
|
||||||
ctx.path = prev;
|
ctx.path = prev;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user