Skip to content

Commit 05a0f21

Browse files
committed
Update proxy path passthrough documentation
Includes updated create-react-app docs. Closes #2565
1 parent c08e3bb commit 05a0f21

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

docs/FAQ.md

+16-12
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
- [Sub-paths](#sub-paths)
1717
- [Sub-domains](#sub-domains)
1818
- [Why does the code-server proxy strip `/proxy/<port>` from the request path?](#why-does-the-code-server-proxy-strip-proxyport-from-the-request-path)
19+
- [Proxying to Create React App](#proxying-to-create-react-app)
1920
- [Multi-tenancy](#multi-tenancy)
2021
- [Docker in code-server container?](#docker-in-code-server-container)
2122
- [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
226227
to the base path as you cannot use relative redirects correctly anymore. See the above
227228
link.
228229
229-
For users who are ok with this tradeoff, pass `--proxy-path-passthrough` to code-server
230-
and the path will be passed as is.
230+
For users who are ok with this tradeoff, use `/absproxy` instead and the path will be
231+
passed as is. e.g. `/absproxy/3000/my-app-path`
231232
232-
This is particularly a problem with the `start` script in create-react-app. See
233+
### Proxying to Create React App
234+
235+
You must use `/absproxy/<port>` with create-react-app.
236+
See [#2565](https://github.com/cdr/code-server/issues/2565) and
233237
[#2222](https://github.com/cdr/code-server/issues/2222). You will need to inform
234-
create-react-app of the path at which you are serving via `homepage` field in your
235-
`package.json`. e.g. you'd add the following for the default CRA port:
238+
create-react-app of the path at which you are serving via `$PUBLIC_URL` and webpack
239+
via `$WDS_SOCKET_PATH`.
236240
237-
```json
238-
"homepage": "/proxy/3000",
241+
e.g.
242+
243+
```sh
244+
PUBLIC_URL=/absproxy/3000 \
245+
WDS_SOCKET_PATH=$PUBLIC_URL/sockjs-node \
246+
BROWSER=none yarn start
239247
```
240248

241-
Then visit `https://my-code-server-address.io/proxy/3000` to see your app exposed through
249+
Then visit `https://my-code-server-address.io/absproxy/3000` to see your app exposed through
242250
code-server!
243251

244-
Unfortunately `webpack-dev-server`'s websocket connections will not go through as it
245-
always uses `/sockjs-node`. So hot reloading will not work until the `create-react-app`
246-
team fix this bug.
247-
248252
Highly recommend using the subdomain approach instead to avoid this class of issue.
249253

250254
## Multi-tenancy

src/node/proxy.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ proxy.on("error", (error, _, res) => {
99
})
1010

1111
// Intercept the response to rewrite absolute redirects against the base path.
12-
// Is disabled when the request has no base path which means --proxy-path-passthrough has
13-
// been enabled.
12+
// Is disabled when the request has no base path which means /absproxy is in use.
1413
proxy.on("proxyRes", (res, req) => {
1514
if (res.headers.location && res.headers.location.startsWith("/") && (req as any).base) {
1615
res.headers.location = (req as any).base + res.headers.location

0 commit comments

Comments
 (0)