From 58d72d53a1cb36fb39592bdaaea2e37106fadebf Mon Sep 17 00:00:00 2001 From: Anmol Sethi Date: Wed, 20 Jan 2021 17:32:47 -0500 Subject: [PATCH] routes/index.ts: register proxy routes before body-parser 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 --- src/node/routes/index.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/node/routes/index.ts b/src/node/routes/index.ts index 00654367..a3fb8bd4 100644 --- a/src/node/routes/index.ts +++ b/src/node/routes/index.ts @@ -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. @@ -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) @@ -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)