diff --git a/src/node/routes/domainProxy.ts b/src/node/routes/domainProxy.ts index 8f0537acc..fc0f91dad 100644 --- a/src/node/routes/domainProxy.ts +++ b/src/node/routes/domainProxy.ts @@ -53,7 +53,7 @@ const maybeProxy = (req: Request): string | undefined => { return undefined } -router.all("*", async (req, res, next) => { +router.all(/.*/, async (req, res, next) => { const port = maybeProxy(req) if (!port) { return next() @@ -97,7 +97,7 @@ router.all("*", async (req, res, next) => { export const wsRouter = WsRouter() -wsRouter.ws("*", async (req, _, next) => { +wsRouter.ws(/.*/, async (req, _, next) => { const port = maybeProxy(req) if (!port) { return next() diff --git a/src/node/routes/index.ts b/src/node/routes/index.ts index a235c4252..9c494a546 100644 --- a/src/node/routes/index.ts +++ b/src/node/routes/index.ts @@ -109,21 +109,21 @@ export const register = async (app: App, args: DefaultedArgs): Promise { + app.router.all("/proxy/:port/:path(.*)?", async (req, res) => { await pathProxy.proxy(req, res) }) - app.wsRouter.get("/proxy/(:port)(/*)?", async (req) => { + app.wsRouter.get("/proxy/:port/:path(.*)?", async (req) => { await pathProxy.wsProxy(req as pluginapi.WebsocketRequest) }) // These two routes pass through the path directly. // So the proxied app must be aware it is running // under /absproxy// - app.router.all("/absproxy/(:port)(/*)?", async (req, res) => { + app.router.all("/absproxy/:port/:path(.*)?", async (req, res) => { await pathProxy.proxy(req, res, { passthroughPath: true, }) }) - app.wsRouter.get("/absproxy/(:port)(/*)?", async (req) => { + app.wsRouter.get("/absproxy/:port/:path(.*)?", async (req) => { await pathProxy.wsProxy(req as pluginapi.WebsocketRequest, { passthroughPath: true, }) diff --git a/src/node/routes/pathProxy.ts b/src/node/routes/pathProxy.ts index a2281eab0..7f69bcf9e 100644 --- a/src/node/routes/pathProxy.ts +++ b/src/node/routes/pathProxy.ts @@ -22,7 +22,7 @@ export async function proxy( if (!(await authenticated(req))) { // If visiting the root (/:port only) redirect to the login page. - if (!req.params[0] || req.params[0] === "/") { + if (!req.params.path || req.params.path === "/") { const to = self(req) return redirect(req, res, "login", { to: to !== "/" ? to : undefined, diff --git a/src/node/routes/vscode.ts b/src/node/routes/vscode.ts index b9ee2c13b..c4f2808a5 100644 --- a/src/node/routes/vscode.ts +++ b/src/node/routes/vscode.ts @@ -205,8 +205,8 @@ export class CodeServerRouteWrapper { this.router.get("/", this.ensureCodeServerLoaded, this.$root) this.router.get("/manifest.json", this.manifest) this.router.post("/mint-key", this.mintKey) - this.router.all("*", ensureAuthenticated, this.ensureCodeServerLoaded, this.$proxyRequest) - this._wsRouterWrapper.ws("*", ensureOrigin, ensureAuthenticated, this.ensureCodeServerLoaded, this.$proxyWebsocket) + this.router.all(/.*/, ensureAuthenticated, this.ensureCodeServerLoaded, this.$proxyRequest) + this._wsRouterWrapper.ws(/.*/, ensureOrigin, ensureAuthenticated, this.ensureCodeServerLoaded, this.$proxyWebsocket) } dispose() { diff --git a/test/unit/node/proxy.test.ts b/test/unit/node/proxy.test.ts index fc347ff83..9e8017e37 100644 --- a/test/unit/node/proxy.test.ts +++ b/test/unit/node/proxy.test.ts @@ -199,7 +199,7 @@ describe("proxy", () => { }) it("should proxy non-ASCII", async () => { - e.get("*", (req, res) => { + e.get(/.*/, (req, res) => { res.json("ほげ") }) codeServer = await integration.setup(["--auth=none"], "") @@ -211,7 +211,7 @@ describe("proxy", () => { it("should not double-encode query variables", async () => { const spy = jest.fn() - e.get("*", (req, res) => { + e.get(/.*/, (req, res) => { spy([req.originalUrl, req.query]) res.end() })