Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: introduce --abs-proxy-base-path that allows app proxying while code-server is not server at the root #6958

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

Merged
code-asher merged 3 commits into coder:main from rafaelnferreira:absproxy-path
Aug 26, 2024

Conversation

Copy link
Contributor

@rafaelnferreira rafaelnferreira commented Aug 25, 2024

What it is

  • Allows proxy traffic to be properly routed when code-server is served under a path.

How

  • Introduces a new switch abs-proxy-base-path.
  • When specified, absproxy requests will be forwarded using the value as prefix

Example

  • Code server is hosted at: my-codeserver.com/user/123
  • React App is started at port 8080 under PUBLIC_PATH /user/123
  • abs-proxy-base-path set to /user/123
  • A GET request to my-codeserver.com/user/123/absproxy/8080/app will properly reach the app.

Fixes #6770

Copy link
Member

@code-asher code-asher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great thank you for implementing!

rafaelnferreira reacted with thumbs up emoji
@code-asher code-asher enabled auto-merge (squash) August 26, 2024 19:24
Copy link

codecov bot commented Aug 26, 2024
edited
Loading

Codecov Report

All modified and coverable lines are covered by tests ✅

Please upload report for BASE (main@39ce82a). Learn more about missing BASE report.
Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@ Coverage Diff @@
## main #6958 +/- ##
=======================================
 Coverage ? 72.63% 
=======================================
 Files ? 31 
 Lines ? 1904 
 Branches ? 412 
=======================================
 Hits ? 1383 
 Misses ? 441 
 Partials ? 80 
Files Coverage Δ
src/node/cli.ts 90.90% <ø> (ø)
src/node/routes/index.ts 76.41% <ø> (ø)
src/node/routes/pathProxy.ts 82.14% <100.00%> (ø)

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 39ce82a...71d10b1. Read the comment docs.

Copy link
Member

code-asher commented Aug 26, 2024
edited
Loading

Looks like our formatter is being a bit weird, let me fix it real quick

Edit: actually not sure what is going on, CI seems to format a little differently compared to local...I will undo the indentation for now and figure it out later.

Not sure why it keeps trying to indent the options though, in CI it
wants it flat. Going to keep it flat for now until we figure it out.
@code-asher code-asher merged commit 4a70389 into coder:main Aug 26, 2024
10 checks passed
@rafaelnferreira rafaelnferreira deleted the absproxy-path branch September 1, 2024 08:45
Copy link

yuzhuoheng commented Oct 14, 2024
edited
Loading

abs-proxy-base-path It didn't work. This is my startup command:
企业微信截图_17288752683468
I tried to open it with a browser, and the page prompt was as follows:
企业微信截图_1728875413984

Copy link
Member

code-asher commented Oct 15, 2024
edited
Loading

This flag is just for code-server's built-in proxy (to proxy to other applications on the remote), not for code-server itself.

To serve code-server itself at a base path, you should use a reverse proxy like NGINX or Caddy.

Copy link

@code-asher i've went through the related issue as well, and i wanted to know if you plan to make sub-path routing available OOB:
for example, allow serving on:https://blabla.com/testing/code-server/
instead of the currently expected FQDN: https://code-server.blabla.com/
without configuring reverse-proxy or any 3rd party tools.
This would be a great addition :) i'd be happy to contribute it myself as well, just wanted know your opinion first.

Copy link
Member

No plans; at the moment our stance is that a reverse proxy should be used!

But, if you have a compelling argument do let me know. From what I understand, it does not make sense to have this capability in code-server because you would have to listen on port 80/443, which means nothing else can be there, which means you might as well serve at the root anyway? So to use sub-path routing, you really need a reverse proxy to have it make any sense anyway.

Copy link

itay-nvn-nv commented Nov 14, 2024
edited
Loading

@code-asher gotcha

attaching here a deploy+svc+ingress manifest that worked for me when attempting to launch code-server on a sub-path, for future reference:

---
apiVersion: apps/v1
kind: Deployment
metadata:
 name: code-server
spec:
 replicas: 1
 selector:
 matchLabels:
 app: code-server
 template:
 metadata:
 labels:
 app: code-server
 spec:
 containers:
 - name: code-server
 image: ghcr.io/coder/code-server:latest
 ports:
 - containerPort: 8080
 env:
 - name: PASSWORD
 value: "your-password-here"
 - name: SUDO_PASSWORD
 value: "your-sudo-password-here"
 - name: BASE_URL
 value: /hello/world
---
apiVersion: v1
kind: Service
metadata:
 name: code-server
spec:
 selector:
 app: code-server
 ports:
 - port: 80
 targetPort: 8080
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
 name: code-server
 annotations:
 kubernetes.io/ingress.class: nginx
 nginx.ingress.kubernetes.io/rewrite-target: /1ドル
spec:
 rules:
 - host: your.domain.com
 http:
 paths:
 - path: /hello/world/?(.*)
 pathType: ImplementationSpecific
 backend:
 service:
 name: code-server
 port:
 number: 80

this will allow to serve your code-server container at https://your.domain.com/hello/world/

code-asher reacted with thumbs up emoji

Copy link

I want to serve code-server on a subpath like /code, but the ci/helm-chart can't edit pathType in values.yaml, which resulting in inability to rewrite.

I think it would be great if it could natively support subpath.

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

@code-asher code-asher code-asher approved these changes

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

Add --base-path flag for use with absolute proxy

AltStyle によって変換されたページ (->オリジナル) /