Repository navigation
code-server's reverse proxy seems to always return index.html for all resources #2222
Description
Activity
code-server rewrites the URL by stripping the base out when proxying so when a request is made for
code-server.tld/proxy/3000/static/js/main.chunk.jsit rewrites that tolocalhost:3000/static/js/main.chunk.js.It looks like
create-react-appis expecting the base path to not be stripped out (localhost:3000/proxy/3000/static/js/main.chunk.js) so the request is a 404 and it serves the root HTML for 404s.So I think we need some kind of mechanism for deciding when we should rewrite the URL and when we shouldn't although maybe we should just default to not rewriting it since I think that might be the more common behavior.
I'm having a similar problem, but with flutter. When I try to open https://mydomain.org/code/proxy/8990/ I can see the error:
GET https://mydomain.org/main.dart.js net::ERR_ABORTED 404 (Not Found)Even when trying on my local network, https://192.168.1.94:8443/proxy/8990/ :
GET http://192.168.1.94:8443/main.dart.js net::ERR_ABORTED 404 (Not Found)Looks like is also not expecting the base path to be stripped out.
when we shouldn't although maybe we should just default to not rewriting it since I think that might be the more common behavior.
I think the base path should be adjusted to work behind the proxy correctly. It's the most portable solution as you can easily remove the proxy in front and your app will still work if you access it locally.
I do think it'd be useful to check what popular proxies do by default.
Hey @erlloyd - sorry to hear about the issue! We'll see what we can do about this.
I'm familiar with React but haven't used it with a proxy or "the 'website' field expected by React" that you're referring to.
Do you mind providing steps to reproduce your issue locally (i.e. without Docker)? That'll help me resolve this faster.
Thank you!
- addedwaiting-for-infoWaiting for more information from submitterWaiting for more information from submitter
on Dec 23, 2020 @jsjoeio The problem is actually very easy to repro, I'll list the steps here. The confusion might be that I mistakenly said 'website' field, when I meant the 'homepage' field in
package.json. So here are the repro steps: (Note: I did this repro on macOS Catalina 10.15.7)-
Create a brand new, unchanged react app from
create react app. I used the following command:yarn create react-app basic-cra-spa -
Install code-server with all defaults
brew install code-server -
Start code server
code-server -
Go to
http://localhost:8080and sign in to code-server -
In the code server instance, open the
basic-cra-spafolder that was created earlier -
In the code server instance, open the
package.jsonfile -
Add the following line under
version:"homepage": "http://localhost:8080/proxy/3000", -
In the code server instance, open a terminal and run
yarn start -
Now, notice that if you open a new browser window and navigate to
http://localhost:3000/proxy/3000, the site loads
If you navigate to
http://localhost:8080/proxy/3000(which is going through code-server's proxy) you get the issue I reported.Let me know if that isn't working for you to repro the problem!
Reacted by Joe Previte-
- removedwaiting-for-infoWaiting for more information from submitterWaiting for more information from submitter
on Dec 23, 2020 Awesome @jsjoeio! Thanks for the update and enjoy your vacation.
Reacted by Joe PreviteHey all! I wanted to post an update. This is my first priority this week. I’ve had some laptop issues which should get resolved tomorrow. I have made a little bit of progress though which you can see if you look at the commits for
issue-2222-reverse-proxy.15 remaining items
I think we should look into being able to specify this flag for each workspace / folder separately since there will be some projects that use relative paths, some that don't and restarting the code-server with changed flag is not feasible?
@meetmangukiya Perhaps we could add a second proxy endpoint that passes through the path? Like
/absproxy?- added a commit that references this issue
on Feb 5, 2021 Added in #2674
Reacted by Joe Previte and nikiGGG- added a commit that references this issue
on Feb 5, 2021 @nhooyr this is awesome, thanks! wont need to restart the server now and still have project specific choice between absolute and relative paths
Reacted by Joe Previte- added a commit that references this issue
on Feb 5, 2021 I posted this on stackoverflow because I am one of the many learning react from udemy/youtube with vs code server who get stucked.
https://stackoverflow.com/questions/74010074/solution-for-running-react-web-app-on-visual-studiocode-server-behind-the-prox/74010075#74010075i dont see any option to work with expo cli
@zakrian07 what are you trying to do?
- I’m on expo cli web and trying to do /proxy/19006…On Sat, Jan 21, 2023 at 3:40 AM Joe Previte ***@***.***> wrote: @zakrian07 <https://github.com/zakrian07> what are you trying to do? — Reply to this email directly, view it on GitHub <#2222 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/ABPI5XKXDU3ILMJEIXNK6GDWTMH6FANCNFSM4S2SFARA> . You are receiving this because you were mentioned.Message ID: ***@***.***>
Feel free to open a Discussion with more information and I'd be happy to help!
PUBLIC_URL=/absproxy/3000 WDS_SOCKET_PATH=$PUBLIC_URL/sockjs-node BROWSER=none npm start
This will give you the React app preview instead of npm start with the above command.
Happy Hacking!


code-server --version: 3.5.0 de41646I'm running a vanilla react project created via
create-react-app. I'm trying to use code-server's built-in proxy to view my application. I set my sites 'website' field as expected by react to behttp://<code-server-machine-ip>:8443/proxy/3000. However, when I go to that address, every one of the assets loaded (all .js files, the favicon) seem to be the index.html. I get an error like this in the console:Uncaught SyntaxError: Unexpected token '<' bundle.js:1
This feels like a bug in the proxy layer of code-server, but I'm hoping I just have something configured incorrectly. I'm running code-server via docker image if that makes a difference.