Skip to content

Commit 305348f

Browse files
committed
Improve proxy fallthrough logic
- Use accept header. - Match /login and /login/ exactly. - Match /static/ (trailing slash). - Use req.path. Same result but feels more accurate to me.
1 parent 6ab6cb4 commit 305348f

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

src/node/proxy.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,18 @@ const maybeProxy = (req: Request): string | undefined => {
5050
* through to allow the redirect and login flow.
5151
*/
5252
const shouldFallThrough = (req: Request): boolean => {
53-
// The ideal would be to have a reliable way to detect if this is a request
54-
// for (or originating from) our root or login HTML. But requests for HTML
55-
// don't seem to set any content type.
56-
return (
57-
req.headers["content-type"] !== "application/json" &&
58-
((req.originalUrl.startsWith("/") && req.method === "GET") ||
59-
(req.originalUrl.startsWith("/static") && req.method === "GET") ||
60-
(req.originalUrl.startsWith("/login") && (req.method === "GET" || req.method === "POST")))
61-
)
53+
// See if it looks like a request for the root or login HTML.
54+
if (req.accepts("text/html")) {
55+
if (
56+
(req.path === "/" && req.method === "GET") ||
57+
(/\/login\/?/.test(req.path) && (req.method === "GET" || req.method === "POST"))
58+
) {
59+
return true
60+
}
61+
}
62+
63+
// See if it looks like a request for a static asset.
64+
return req.path.startsWith("/static/") && req.method === "GET"
6265
}
6366

6467
router.all("*", (req, res, next) => {

0 commit comments

Comments
 (0)