Skip to content

code-server's reverse proxy seems to always return index.html for all resources #2222

Closed
@erlloyd

Description

@erlloyd
  • 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

Screen Shot 2020-10-21 at 9 36 54 PM

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

code-asher commented on Oct 22, 2020

@code-asher
Member

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 to localhost: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

Gilinho commented on Nov 27, 2020

@Gilinho

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

nhooyr commented on Dec 8, 2020

@nhooyr
Contributor

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.

self-assigned this
on Dec 23, 2020
jsjoeio

jsjoeio commented on Dec 23, 2020

@jsjoeio
Contributor

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

erlloyd commented on Dec 23, 2020

@erlloyd
Author

@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)

  1. Create a brand new, unchanged react app from create react app. I used the following command: yarn create react-app basic-cra-spa

  2. Install code-server with all defaults brew install code-server

  3. Start code server code-server

  4. Go to http://localhost:8080 and sign in to code-server

  5. In the code server instance, open the basic-cra-spa folder that was created earlier

  6. In the code server instance, open the package.json file

  7. Add the following line under version: "homepage": "http://localhost:8080/proxy/3000",

  8. In the code server instance, open a terminal and run yarn start

  9. 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!

jsjoeio

jsjoeio commented on Dec 23, 2020

@jsjoeio
Contributor

@erlloyd Thanks a ton for the quick response and the detailed steps 🙏

I was able to reproduce it locally.

image

I'll see what options we have to fix this.

jsjoeio

jsjoeio commented on Dec 23, 2020

@jsjoeio
Contributor

Update: I was able to get it working.

image

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

erlloyd commented on Dec 27, 2020

@erlloyd
Author

Awesome @jsjoeio! Thanks for the update and enjoy your vacation.

jsjoeio

jsjoeio commented on Jan 5, 2021

@jsjoeio
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions

    code-server's reverse proxy seems to always return index.html for all resources · Issue #2222 · coder/code-server