Update proxy path passthrough documentation
Includes updated create-react-app docs. Closes #2565
This commit is contained in:
parent
c08e3bb06d
commit
05a0f213a7
28
docs/FAQ.md
28
docs/FAQ.md
|
@ -16,6 +16,7 @@
|
|||
- [Sub-paths](#sub-paths)
|
||||
- [Sub-domains](#sub-domains)
|
||||
- [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)
|
||||
- [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/<port>` 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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue