mirror of https://git.tuxpa.in/a/code-server.git
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.
This commit is contained in:
parent
6ab6cb4f07
commit
305348f0ac
|
@ -50,15 +50,18 @@ const maybeProxy = (req: Request): string | undefined => {
|
||||||
* through to allow the redirect and login flow.
|
* through to allow the redirect and login flow.
|
||||||
*/
|
*/
|
||||||
const shouldFallThrough = (req: Request): boolean => {
|
const shouldFallThrough = (req: Request): boolean => {
|
||||||
// The ideal would be to have a reliable way to detect if this is a request
|
// See if it looks like a request for the root or login HTML.
|
||||||
// for (or originating from) our root or login HTML. But requests for HTML
|
if (req.accepts("text/html")) {
|
||||||
// don't seem to set any content type.
|
if (
|
||||||
return (
|
(req.path === "/" && req.method === "GET") ||
|
||||||
req.headers["content-type"] !== "application/json" &&
|
(/\/login\/?/.test(req.path) && (req.method === "GET" || req.method === "POST"))
|
||||||
((req.originalUrl.startsWith("/") && req.method === "GET") ||
|
) {
|
||||||
(req.originalUrl.startsWith("/static") && req.method === "GET") ||
|
return true
|
||||||
(req.originalUrl.startsWith("/login") && (req.method === "GET" || req.method === "POST")))
|
}
|
||||||
)
|
}
|
||||||
|
|
||||||
|
// See if it looks like a request for a static asset.
|
||||||
|
return req.path.startsWith("/static/") && req.method === "GET"
|
||||||
}
|
}
|
||||||
|
|
||||||
router.all("*", (req, res, next) => {
|
router.all("*", (req, res, next) => {
|
||||||
|
|
Loading…
Reference in New Issue