Skip to content

Commit

Permalink
routes/index.ts: register proxy routes before body-parser
Browse files Browse the repository at this point in the history
Any json or urlencoded request bodies were being consumed by body-parser
before they could be proxied. That's why requests without Content-Type
were proxied correctly as body-parser would not consume their body.

This allows the http-proxy package to passthrough the request body correctly
in all instances.

Closes #2377
  • Loading branch information
nhooyr committed Feb 1, 2021
1 parent 23b81ff commit 92604d9
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/node/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,6 @@ export const register = async (
app.use(cookieParser())
wsApp.use(cookieParser())

app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: true }))

const common: express.RequestHandler = (req, _, next) => {
// /healthz|/healthz/ needs to be excluded otherwise health checks will make
// it look like code-server is always in use.
Expand Down Expand Up @@ -106,6 +103,12 @@ export const register = async (
app.use("/", domainProxy.router)
wsApp.use("/", domainProxy.wsRouter.router)

app.use("/proxy", proxy.router)
wsApp.use("/proxy", proxy.wsRouter.router)

app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: true }))

app.use("/", vscode.router)
wsApp.use("/", vscode.wsRouter.router)
app.use("/vscode", vscode.router)
Expand All @@ -121,9 +124,6 @@ export const register = async (
})
}

app.use("/proxy", proxy.router)
wsApp.use("/proxy", proxy.wsRouter.router)

app.use("/static", _static.router)
app.use("/update", update.router)

Expand Down

0 comments on commit 92604d9

Please sign in to comment.