fix: failed to dynamically load chunk (#19821)

This commit is contained in:
Marc Roig 2024-03-18 15:18:05 +01:00 committed by GitHub
parent 1cb89ea8d0
commit 1e7fe8ee8c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -20,23 +20,16 @@ const watch = async (ctx: BuildContext): Promise<ViteWatcher> => {
const vite = await createServer(finalConfig); const vite = await createServer(finalConfig);
ctx.strapi.server.app.use(async (ctx, next) => { ctx.strapi.server.app.use((ctx, next) => {
const url = ctx.url;
// Check if the URL points to a file that Vite can handle
const file = await vite.moduleGraph.getModuleByUrl(url);
if (file || url.startsWith('/@')) {
// If Vite can handle the file, pass the request to the Vite middleware
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
vite.middlewares(ctx.req, ctx.res, (err: unknown) => { vite.middlewares(ctx.req, ctx.res, (err: unknown) => {
if (err) reject(err); if (err) {
else resolve(next()); reject(err);
}); } else {
}); resolve(next());
} }
});
await next(); });
}); });
const serveAdmin: Common.MiddlewareHandler = async (koaCtx, next) => { const serveAdmin: Common.MiddlewareHandler = async (koaCtx, next) => {