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

Allow specifying subdirectory to open when port forwarding detected #413

Open
heaths opened this issue Feb 7, 2024 · 13 comments
Open

Allow specifying subdirectory to open when port forwarding detected #413

heaths opened this issue Feb 7, 2024 · 13 comments

Comments

@heaths
Copy link

heaths commented Feb 7, 2024

We would like a way to configure a path (subdirectory) of a site to open from a devcontainer. In VSCode, for example, clicking the browse button - or from the automatic prompt to open a browser when a port is forwarded - we could open a site like http://127.0.0.1:4000/azure-sdk instead of only http://127.0.0.1:4000. For GitHub Codespaces, this would be forwarded port to a remote continer.

To portAttributes or otherPortAttributes, this would add:

Property Type Description
path string Optional path relative to the site root to open in a browser e.g., "/blog" on forwarded port 4000 would open http://127.0.0.1:4000/blog on localhost.

To the schema for both portAttributes or otherPortAttributes1, this would look like:

"portsAttributes": {
    "type": "object",
    "patternProperties": {
            "(^\\d+(-\\d+)?$)|(.+)": {
                    "type": "object",
                    "description": "A port, range of ports (ex. \"40000-55000\"), or regular expression (ex. \".+\\\\/server.js\").  For a port number or range, the attributes will apply to that port number or range of port numbers. Attributes which use a regular expression will apply to ports whose associated process command line matches the expression.",
                    "properties": {
+                      "path": {
+                          "type": "string",
+                          "description": "Optional path relative to the site root to open in a browser e.g., '/blog' on forwarded port 4000 would open `http://127.0.0.1:4000/blog` on localhost."
+                      },
                       "onAutoForward": {

See microsoft/vscode-remote-release#9518 for additional context.

1 Since portAttributes and otherPortAttributes appear to be the same schema, wouldn't a $ref to a single object definition be sufficient and easier to maintain?

@samruddhikhandale
Copy link
Member

Hi 👋

This sounds cool, thanks for putting this up 💡

Quick clarifying question, as portsAttributes apply to all the ports specified in forwardPorts property. Is this something you are expecting? or do you prefer to only add path property to certain/specific forwarded ports?

@heaths
Copy link
Author

heaths commented Feb 8, 2024

Quick clarifying question, as portsAttributes apply to all the ports specified in forwardPorts property. Is this something you are expecting? or do you prefer to only add path property to certain/specific forwarded ports?

How do they apply to all ports when you're required to specify a port specification (single integer or string range) e.g.,

"portAttributes": {
  "4000": {
    "path": "/azure-sdk"
  }
}

I certainly wouldn't want this to apply to all ports specified in the "forwardPorts": [] array.

@samruddhikhandale
Copy link
Member

samruddhikhandale commented Feb 23, 2024

Thanks for clarifying, your request makes sense to me.
Along with the cli, spec and schema changes, I believe this will also require a change in VS Code, looping in @chrmarti for his insights.

@chrmarti
Copy link
Contributor

/cc @alexr00 for the VS Code side.

@SteveBombardier
Copy link

@SteveBombardier
Copy link

Je sais pas comment faire

@alexr00
Copy link

alexr00 commented Feb 27, 2024

This seems reasonable to me!

@heaths
Copy link
Author

heaths commented Feb 27, 2024

This seems reasonable to me!

@alexr00 what would be the next steps? Is this something you'd like help with, if I can? I looked in the VSCode repo originally and didn't find any code that seemed to process portAttributes - just the schemas or something. I may have time for working on this.

@chrmarti
Copy link
Contributor

chrmarti commented Mar 5, 2024

@samruddhikhandale @alexr00 Is this something Codespaces can adopt too? I remember the implementation there to be more involved than when the VS Code UI runs in a local window.

@samruddhikhandale
Copy link
Member

@samruddhikhandale @alexr00 Is this something Codespaces can adopt too? I remember the implementation there to be more involved than when the VS Code UI runs in a local window.

Looping in @osortega who can help answer this question.

@alexr00
Copy link

alexr00 commented Mar 6, 2024

The next steps:

  1. Find someone to do the work to support this. That would usually be me. I can see if we can fit it into an upcoming plan, or someone else can work on it and I'd accept a PR.
  2. Do the work to support this from the remote.portsAttributes VS Code setting. Code pointer: https://github.com/microsoft/vscode/blob/573a9ff995c4a63624eede783d6daa99da01c012/src/vs/workbench/services/remote/common/tunnelModel.ts#L192-L193
  3. Once this is supported by VS Code I think it makes sense to add support to devcontainers schema.

@alexr00 Is this something Codespaces can adopt too? I remember the implementation there to be more involved than when the VS Code UI runs in a local window.

I would expect that there should be any additional work from Codespaces to make this happen. This would just be a property in the portsAttributes setting, and I think we should be able handle everything else from within VS Code. I would need to check how things currently work in Codespaces in the browser, but so long as they already support navigating to a subdirectory it should be fine.

@heaths when would you expect the subdirectory to be applied?

  • When the url opened from the Ports view? (very doable)
  • When the url is opened from an onAutoForward action in the portsAttributes? (very doable)
  • When the url is opened from clicking on a link in the terminal (even if that link doesn't include the subdirectory)? (harder to do)
  • Any other places?

@heaths
Copy link
Author

heaths commented Mar 6, 2024

  • When the url opened from the Ports view? (very doable)
  • When the url is opened from an onAutoForward action in the portsAttributes? (very doable)

Just those two. The link in the terminal window - at least as output from jekyll serve - is already correct e.g., http://localhost:4000/azure-sdk.

I'd be happy to submit PRs to respective repos, but it seems all those - including the one you linked to that I found previously - are just parsing/processing the config. Is the code that actually uses it and does all the forwarding / browser work elsewhere? Is that internal/private and would need to be done by you or someone on your team?

@alexr00
Copy link

alexr00 commented Mar 7, 2024

I don't think we actually need to make any changes to how the port is forwarded. If a process is listening at localhost:4000 on the remote machine and you want to access http://localhost:4000/azure-sdk, then we should be able to just forward localhost:4000 locally to localhost:4000 then adding a path like /azure-sdk should "just work".

The thing that we need to do is make sure to append the path (eg. /azure-sdk) to the local URI in the correct places:

I would suggest adding a preferredPath property here:

https://github.com/microsoft/vscode/blob/68f565d32a8248b1c5677426621c34a875c1a8da/src/vs/workbench/services/remote/common/tunnelModel.ts#L49-L66

Updating the parsing somewhere here:

https://github.com/microsoft/vscode/blob/68f565d32a8248b1c5677426621c34a875c1a8da/src/vs/workbench/services/remote/common/tunnelModel.ts#L217-L251

The merging of attributes here:
https://github.com/microsoft/vscode/blob/68f565d32a8248b1c5677426621c34a875c1a8da/src/vs/workbench/services/remote/common/tunnelModel.ts#L964-L965

Then ensuring the preferredPath gets applied correctly here:

https://github.com/microsoft/vscode/blob/68f565d32a8248b1c5677426621c34a875c1a8da/src/vs/workbench/services/remote/common/tunnelModel.ts#L720-L734

here:

https://github.com/microsoft/vscode/blob/68f565d32a8248b1c5677426621c34a875c1a8da/src/vs/workbench/services/remote/common/tunnelModel.ts#L482-L497

and here:

https://github.com/microsoft/vscode/blob/68f565d32a8248b1c5677426621c34a875c1a8da/src/vs/workbench/services/remote/common/tunnelModel.ts#L449-L468

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants