Closed
Description
- Web Browser: Chrome 86
- Local OS: Mac OS X
- Remote OS: Ubuntu 20.04 (using docker)
- Remote Architecture:
code-server --version
: 3.5.0 de41646
I'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 be http://<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.
Activity
code-asher commentedon Oct 22, 2020
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.js
it rewrites that tolocalhost:3000/static/js/main.chunk.js
.It looks like
create-react-app
is 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.
Gilinho commentedon Nov 27, 2020
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.
nhooyr commentedon Dec 8, 2020
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.
jsjoeio commentedon Dec 23, 2020
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!
erlloyd commentedon 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:8080
and sign in to code-serverIn the code server instance, open the
basic-cra-spa
folder that was created earlierIn the code server instance, open the
package.json
fileAdd 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 loadsIf 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!
jsjoeio commentedon Dec 23, 2020
@erlloyd Thanks a ton for the quick response and the detailed steps 🙏
I was able to reproduce it locally.
I'll see what options we have to fix this.
jsjoeio commentedon Dec 23, 2020
Update: I was able to get it working.
I need to write some tests and figure out how we want the base path to be adjusted moving forward. I'll be on vacation until the 4th but should be able to get a PR up that week.
erlloyd commentedon Dec 27, 2020
Awesome @jsjoeio! Thanks for the update and enjoy your vacation.
jsjoeio commentedon Jan 5, 2021
Hey 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
.35 remaining items