Skip to content

Commit b8d830b

Browse files
committed
Update path syntax for Express
It seems that * matches a literal * now, so we have to use a regular expression. Parentheses around a parameter no longer works (it causes it to match on the parameter name literally) and I am not sure why we had it anyway as it had no effect previously. Matching with a leading / does not appear to work either, but we do not need the leading / anyway since the proxy logic was changed to use the whole path. Consequently it will never be / anymore from what I can tell but I left that check in just in case. I turned it into a named parameter as well, because that seems better.
1 parent 417c1f3 commit b8d830b

File tree

5 files changed

+11
-11
lines changed

5 files changed

+11
-11
lines changed

src/node/routes/domainProxy.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ const maybeProxy = (req: Request): string | undefined => {
5353
return undefined
5454
}
5555

56-
router.all("*", async (req, res, next) => {
56+
router.all(/.*/, async (req, res, next) => {
5757
const port = maybeProxy(req)
5858
if (!port) {
5959
return next()
@@ -97,7 +97,7 @@ router.all("*", async (req, res, next) => {
9797

9898
export const wsRouter = WsRouter()
9999

100-
wsRouter.ws("*", async (req, _, next) => {
100+
wsRouter.ws(/.*/, async (req, _, next) => {
101101
const port = maybeProxy(req)
102102
if (!port) {
103103
return next()

src/node/routes/index.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -109,21 +109,21 @@ export const register = async (app: App, args: DefaultedArgs): Promise<Disposabl
109109
app.router.use("/", domainProxy.router)
110110
app.wsRouter.use("/", domainProxy.wsRouter.router)
111111

112-
app.router.all("/proxy/(:port)(/*)?", async (req, res) => {
112+
app.router.all("/proxy/:port/:path(.*)?", async (req, res) => {
113113
await pathProxy.proxy(req, res)
114114
})
115-
app.wsRouter.get("/proxy/(:port)(/*)?", async (req) => {
115+
app.wsRouter.get("/proxy/:port/:path(.*)?", async (req) => {
116116
await pathProxy.wsProxy(req as pluginapi.WebsocketRequest)
117117
})
118118
// These two routes pass through the path directly.
119119
// So the proxied app must be aware it is running
120120
// under /absproxy/<someport>/
121-
app.router.all("/absproxy/(:port)(/*)?", async (req, res) => {
121+
app.router.all("/absproxy/:port/:path(.*)?", async (req, res) => {
122122
await pathProxy.proxy(req, res, {
123123
passthroughPath: true,
124124
})
125125
})
126-
app.wsRouter.get("/absproxy/(:port)(/*)?", async (req) => {
126+
app.wsRouter.get("/absproxy/:port/:path(.*)?", async (req) => {
127127
await pathProxy.wsProxy(req as pluginapi.WebsocketRequest, {
128128
passthroughPath: true,
129129
})

src/node/routes/pathProxy.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export async function proxy(
2222

2323
if (!(await authenticated(req))) {
2424
// If visiting the root (/:port only) redirect to the login page.
25-
if (!req.params[0] || req.params[0] === "/") {
25+
if (!req.params.path || req.params.path === "/") {
2626
const to = self(req)
2727
return redirect(req, res, "login", {
2828
to: to !== "/" ? to : undefined,

src/node/routes/vscode.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,8 @@ export class CodeServerRouteWrapper {
205205
this.router.get("/", this.ensureCodeServerLoaded, this.$root)
206206
this.router.get("/manifest.json", this.manifest)
207207
this.router.post("/mint-key", this.mintKey)
208-
this.router.all("*", ensureAuthenticated, this.ensureCodeServerLoaded, this.$proxyRequest)
209-
this._wsRouterWrapper.ws("*", ensureOrigin, ensureAuthenticated, this.ensureCodeServerLoaded, this.$proxyWebsocket)
208+
this.router.all(/.*/, ensureAuthenticated, this.ensureCodeServerLoaded, this.$proxyRequest)
209+
this._wsRouterWrapper.ws(/.*/, ensureOrigin, ensureAuthenticated, this.ensureCodeServerLoaded, this.$proxyWebsocket)
210210
}
211211

212212
dispose() {

test/unit/node/proxy.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ describe("proxy", () => {
199199
})
200200

201201
it("should proxy non-ASCII", async () => {
202-
e.get("*", (req, res) => {
202+
e.get(/.*/, (req, res) => {
203203
res.json("ほげ")
204204
})
205205
codeServer = await integration.setup(["--auth=none"], "")
@@ -211,7 +211,7 @@ describe("proxy", () => {
211211

212212
it("should not double-encode query variables", async () => {
213213
const spy = jest.fn()
214-
e.get("*", (req, res) => {
214+
e.get(/.*/, (req, res) => {
215215
spy([req.originalUrl, req.query])
216216
res.end()
217217
})

0 commit comments

Comments
 (0)