mirror of
https://github.com/strapi/strapi.git
synced 2025-11-03 03:17:11 +00:00
fix: virtual prefix proxy path for vite middleware to work
This commit is contained in:
parent
110b429be2
commit
c2680dea29
@ -57,10 +57,21 @@ const watch = async (ctx: BuildContext): Promise<ViteWatcher> => {
|
||||
|
||||
const viteMiddlewares: Core.MiddlewareHandler = (koaCtx, next) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const prefix = ctx.basePath.replace(ctx.adminPath, '').replace(/\/+$/, '');
|
||||
|
||||
const originalPath = koaCtx.path;
|
||||
if (!koaCtx.path.startsWith(prefix)) {
|
||||
koaCtx.path = `${prefix}${koaCtx.path}`;
|
||||
}
|
||||
|
||||
vite.middlewares(koaCtx.req, koaCtx.res, (err: unknown) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
} else {
|
||||
if (!koaCtx.res.headersSent) {
|
||||
koaCtx.path = originalPath;
|
||||
}
|
||||
|
||||
resolve(next());
|
||||
}
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user