From 05a0f213a7ac2e4e5ade3ab7252d09fad422cb3f Mon Sep 17 00:00:00 2001 From: Anmol Sethi Date: Fri, 5 Feb 2021 02:31:18 -0500 Subject: [PATCH] Update proxy path passthrough documentation Includes updated create-react-app docs. Closes #2565 --- docs/FAQ.md | 28 ++++++++++++++++------------ src/node/proxy.ts | 3 +-- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/docs/FAQ.md b/docs/FAQ.md index 94535bd0..61185522 100644 --- a/docs/FAQ.md +++ b/docs/FAQ.md @@ -16,6 +16,7 @@ - [Sub-paths](#sub-paths) - [Sub-domains](#sub-domains) - [Why does the code-server proxy strip `/proxy/` from the request path?](#why-does-the-code-server-proxy-strip-proxyport-from-the-request-path) + - [Proxying to Create React App](#proxying-to-create-react-app) - [Multi-tenancy](#multi-tenancy) - [Docker in code-server container?](#docker-in-code-server-container) - [How can I disable telemetry?](#how-can-i-disable-telemetry) @@ -226,25 +227,28 @@ However many people prefer the cleaner aesthetic of no trailing slashes. This co to the base path as you cannot use relative redirects correctly anymore. See the above link. -For users who are ok with this tradeoff, pass `--proxy-path-passthrough` to code-server -and the path will be passed as is. +For users who are ok with this tradeoff, use `/absproxy` instead and the path will be +passed as is. e.g. `/absproxy/3000/my-app-path` -This is particularly a problem with the `start` script in create-react-app. See +### Proxying to Create React App + +You must use `/absproxy/` with create-react-app. +See [#2565](https://github.com/cdr/code-server/issues/2565) and [#2222](https://github.com/cdr/code-server/issues/2222). You will need to inform -create-react-app of the path at which you are serving via `homepage` field in your -`package.json`. e.g. you'd add the following for the default CRA port: +create-react-app of the path at which you are serving via `$PUBLIC_URL` and webpack +via `$WDS_SOCKET_PATH`. -```json - "homepage": "/proxy/3000", +e.g. + +```sh +PUBLIC_URL=/absproxy/3000 \ + WDS_SOCKET_PATH=$PUBLIC_URL/sockjs-node \ + BROWSER=none yarn start ``` -Then visit `https://my-code-server-address.io/proxy/3000` to see your app exposed through +Then visit `https://my-code-server-address.io/absproxy/3000` to see your app exposed through code-server! -Unfortunately `webpack-dev-server`'s websocket connections will not go through as it -always uses `/sockjs-node`. So hot reloading will not work until the `create-react-app` -team fix this bug. - Highly recommend using the subdomain approach instead to avoid this class of issue. ## Multi-tenancy diff --git a/src/node/proxy.ts b/src/node/proxy.ts index 35fd5d81..c03d3d5d 100644 --- a/src/node/proxy.ts +++ b/src/node/proxy.ts @@ -9,8 +9,7 @@ proxy.on("error", (error, _, res) => { }) // Intercept the response to rewrite absolute redirects against the base path. -// Is disabled when the request has no base path which means --proxy-path-passthrough has -// been enabled. +// Is disabled when the request has no base path which means /absproxy is in use. proxy.on("proxyRes", (res, req) => { if (res.headers.location && res.headers.location.startsWith("/") && (req as any).base) { res.headers.location = (req as any).base + res.headers.location