Skip to content

Commit 0abec93

Browse files
authored
fix: serve 4xx pages when using dev server (#225)
1 parent dff5acb commit 0abec93

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

src/msha/middlewares/request.middleware.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,22 +93,25 @@ function serveStaticOrProxyReponse(req: http.IncomingMessage, res: http.ServerRe
9393
}
9494

9595
const customUrl = isCustomUrl(req);
96+
logger.silly(`customUrl: ${chalk.yellow(customUrl)}`);
9697
if (req.url?.includes("index.html") || customUrl) {
97-
// serve index.htmn or custom pages from user's `outputLocation`
98+
// serve index.html or custom pages from user's `outputLocation`
9899

99100
logger.silly(`custom page or index.html detected`);
100101
// extract user custom page filename
101102
req.url = req.url?.replace(DEFAULT_CONFIG.customUrlScheme!, "");
102103
target = SWA_CLI_OUTPUT_LOCATION;
103104

104-
logger.silly(` - isCustomUrl: ${chalk.yellow(customUrl)}`);
105105
logger.silly(` - url: ${chalk.yellow(req.url)}`);
106106
logger.silly(` - statusCode: ${chalk.yellow(res.statusCode)}`);
107107
logger.silly(` - target: ${chalk.yellow(target)}`);
108108
}
109109

110+
const is4xx = res.statusCode >= 400 && res.statusCode < 500;
111+
logger.silly(`is4xx: ${is4xx}`);
112+
110113
// if the static app is served by a dev server, forward all requests to it.
111-
if (IS_APP_DEV_SERVER()) {
114+
if (IS_APP_DEV_SERVER() && (!is4xx || customUrl)) {
112115
logger.silly(`remote dev server detected. Proxying request`);
113116
logger.silly(` - url: ${chalk.yellow(req.url)}`);
114117
logger.silly(` - code: ${chalk.yellow(res.statusCode)}`);

0 commit comments

Comments
 (0)