diff --git a/tools/pfe-tools/dev-server/config.ts b/tools/pfe-tools/dev-server/config.ts index 806e9a182f..4fc1c0b067 100644 --- a/tools/pfe-tools/dev-server/config.ts +++ b/tools/pfe-tools/dev-server/config.ts @@ -88,21 +88,13 @@ async function cacheBusterMiddleware(ctx: Context, next: () => Promise) { function liveReloadTsChangesMiddleware( config: ReturnType, ): Middleware { - /** - * capture group 1: - * Either config.elementsDir or `pfe-core` - * `/` - * **ANY** (_>= 0x_) - * `.js` - */ const TYPESCRIPT_SOURCES_RE = new RegExp(`(${config.elementsDir}|pfe-core)/.*\\.js`); - - return function(ctx, next) { - if (!ctx.path.includes('node_modules') && ctx.path - .match(TYPESCRIPT_SOURCES_RE)) { + return async function(ctx, next) { + await next(); + if (ctx.status === 404 + && !ctx.path.includes('node_modules') + && TYPESCRIPT_SOURCES_RE.test(ctx.path)) { ctx.redirect(ctx.path.replace('.js', '.ts')); - } else { - return next(); } }; }