Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

base url support #241

Closed
yamajik opened this issue Mar 14, 2019 · 25 comments · Fixed by #857
Closed

base url support #241

yamajik opened this issue Mar 14, 2019 · 25 comments · Fixed by #857
Labels
waiting-for-info Waiting for more information from submitter

Comments

@yamajik
Copy link
Contributor

yamajik commented Mar 14, 2019

I wanne run behind proxy

@yamajik yamajik added the enhancement Some improvement that isn't a feature label Mar 14, 2019
@MichaelDesantis
Copy link
Contributor

@yamajik I think there are already docs on how to run it behind a proxy https://github.com/codercom/code-server/blob/master/doc/self-hosted/index.md#user-content-nginx-reverse-proxy

@kylecarbs kylecarbs added waiting-for-info Waiting for more information from submitter and removed enhancement Some improvement that isn't a feature labels Mar 14, 2019
@yamajik
Copy link
Contributor Author

yamajik commented Mar 15, 2019

I am managing many code servers behind a proxy.
Each server serves with baseurl like “/code-server/:server_id/“ .
But, some requests still do from root.

@yamajik
Copy link
Contributor Author

yamajik commented Mar 15, 2019

I wanne config for global baseurl setting

@tiffany352
Copy link

I just found code-server, and I want to give it a try, but without base url support it looks like I'll have to setup a separate subdomain for it on my website, which is pretty inconvenient.

@sr229
Copy link
Contributor

sr229 commented Mar 15, 2019

@tiffany352 @yamajik have you tried using Docker with different IPs to see if it works as a temporary workaround? This is possible by creating a new network.

@mgcaret
Copy link

mgcaret commented Mar 15, 2019

I also request this. It's a non-starter if I can't use it at another HTTP path, instead of /.

@sr229 that won't help. The issue is that you cannot set it up to be at http://myserver.foo/vscode/, rather it must be at http://myserver.foo/

@sgama
Copy link

sgama commented Mar 15, 2019

I also would like this functionality to be added in, preferably as an environment variable such as BASE_URL

LetsEncrypt limits the number of SSL certs for subdomains on one host, thus taking up another subdomain is not preferable.

@tiffany352
Copy link

@sgama Off topic, but I'm kind of confused about your LE comment, I don't see any kind of limit other than (large) rate limits on certificate issuing? There's also wildcard certificates available now.

I ended up just making a new subdomain to run code-server on, and it's working fine.

@sgama
Copy link

sgama commented Mar 16, 2019

@tiffany352, oh right. Wildcards are available now. Thanks for reminding me.

@kylecarbs
Copy link
Member

This should be fixed. The socket should now be created at the current page path.

@yamajik
Copy link
Contributor Author

yamajik commented Mar 19, 2019

Not sure.

resourse urls
webview urls
...

Both incorrect.

I have fixed some in my fork.

@yamajik
Copy link
Contributor Author

yamajik commented Mar 19, 2019

reopen this, plz.

@yamajik
Copy link
Contributor Author

yamajik commented Mar 19, 2019

I will pr my fix later which may not fix all.

@chylvina
Copy link

+1

@kylecarbs kylecarbs reopened this Mar 19, 2019
@kylecarbs
Copy link
Member

We'll have to remove the /resource and replace it with resource/ to use subpaths.

@patrickstjohn
Copy link

+1 this will be a big help for us

@patrickstjohn
Copy link

@yamajik Thank you for the PR to add this feature. Any documentation on how we utilize this? Looking at your code it seems like you are fixing up the URLs? So if we have a server running behind a proxy pointing at something like http:///patrickstjohn it would strip off patrickstjohn and things would work as if you were going to / directly?

@au5ton
Copy link

au5ton commented Apr 18, 2019

Index page is redirecting http://hostname/custombaseurl/ to http://hostname/login/ when it should be http://hostname/custombaseurl/login/

https://github.com/codercom/code-server/blob/c3a38e3fea8a28afa4017cf6c45ba12e82ff1feb/packages/server/src/server.ts#L233-L247

@yamajik
Copy link
Contributor Author

yamajik commented Apr 19, 2019

@yamajik Thank you for the PR to add this feature. Any documentation on how we utilize this? Looking at your code it seems like you are fixing up the URLs? So if we have a server running behind a proxy pointing at something like http:///patrickstjohn it would strip off patrickstjohn and things would work as if you were going to / directly?

@patrickstjohn http:///patrickstjohn Correct url?

In my case, I wanne run behind url http://example.com/some/path/to/code/server.

First, run code server on http://localhost:8443
Then, proxy all requrests(both http, https, ws, wss) from http://example.com/some/path/to/code/server to http://localhost:8443 (maybe by nginx)

In my pr, fixed all incorrect frontend urls I found. I should miss some.

@yamajik
Copy link
Contributor Author

yamajik commented Apr 19, 2019

Index page is redirecting http://hostname/custombaseurl/ to http://hostname/login/ when it should be http://hostname/custombaseurl/login/

code-server/packages/server/src/server.ts

Lines 233 to 247 in c3a38e3

// If not authenticated, redirect to the login page.
app.get("/", (req, res, next) => {
if (!isAuthed(req)) {
return redirect(req, res, "login");
}
next();
});

// If already authenticated, redirect back to the root.
app.get("/login", (req, res, next) => {
if (isAuthed(req)) {
return redirect(req, res, "", "login");
}
next();
});

@au5ton Yelp. Miss one.

This is a wrong server url. Using relative path or adding a prefix path config both fix this.
I prefer adding a prefix path config which may cause troubles in development.

Or u can run behind a reverse proxy server and do not mind it.

@au5ton
Copy link

au5ton commented Apr 24, 2019

This block is working correctly for when a baseurl is provided (via the currentUrl variable). Examples I tested with were https://example.com/code/ and https://example.com/my/long/baseurl/.

By working, I mean that
https://example.com/code/ => https://example.com/code/login
https://example.com/code/login => https://example.com/code/
https://example.com/my/long/baseurl/ => https://example.com/my/long/baseurl/login
https://example.com/my/long/baseurl/login => https://example.com/my/long/baseurl/

https://github.com/codercom/code-server/blob/c3a38e3fea8a28afa4017cf6c45ba12e82ff1feb/packages/server/src/server.ts#L193-L211

@AKKlostermann
Copy link

I have succeeded to run code-server in a subpath behind nginx using a rewrite. It mostly seems to work, even without anything "baseurl" related.
´´´
location /vscode {
rewrite /vscode/(.*) /$1 break;
proxy_pass http://vscode:8443;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
}

´´´

@aofei
Copy link

aofei commented May 17, 2019

Has the team considered implementing this feature?

Today is the first day I tried this damn cool project. 🎉 But when I deployed it to my HTTP server, I ran into the same problem. And the #307 doesn't seem to solve the problem of the HTTP request's paths. Now my HTTP server will still receive requests for files such as *.css and *.js under the root path instead of under the /vscode.

@sr229
Copy link
Contributor

sr229 commented May 17, 2019

CC @coadler and @multishifties, looks like this issue is persistent, and we have multiple significant use cases. Recommending escalation.

@MichaelDesantis
Copy link
Contributor

I'll tag Kyle for this one since this feature has been requested a lot.

@kylecarbs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting-for-info Waiting for more information from submitter
Projects
None yet
Development

Successfully merging a pull request may close this issue.

13 participants