Skip to content

Commit

Permalink
Update proxy path passthrough documentation
Browse files Browse the repository at this point in the history
Includes updated create-react-app docs.

Closes coder#2565
  • Loading branch information
nhooyr committed Feb 5, 2021
1 parent 8e4f3d8 commit 28c9e30
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
27 changes: 15 additions & 12 deletions docs/FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,25 +226,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/<port>` instead 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=/absproxy/3000/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
Expand Down
3 changes: 1 addition & 2 deletions src/node/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 28c9e30

Please sign in to comment.