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

x/pkgsite/cmd/pkgsite: Use relative links for static, etc. #66858

Open
spkane opened this issue Apr 16, 2024 · 6 comments
Open

x/pkgsite/cmd/pkgsite: Use relative links for static, etc. #66858

spkane opened this issue Apr 16, 2024 · 6 comments
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. pkgsite

Comments

@spkane
Copy link

spkane commented Apr 16, 2024

What is the URL of the page with the issue?

N/A

What is your user agent?

Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36

Screenshot

CleanShot 2024-04-16 at 12 41 16

What did you do?

When running pkgsite -open . locally in a remote Visual Studio Code terminal (via code-server), a proxy will be started.

https://coder.com/docs/code-server/latest/guide#stripping-proxyport-from-the-request-path

This typically means that the main page will be at https://${hostname}/proxy/8080/ and the static directories will be under the path /proxy/8080/static/. However, it appears that the site always tries to find them under /static, and there is no obvious way to change this.

What did you see happen?

None of the static CSS or images will load.

What did you expect to see?

All of the static CSS and images load.

@spkane spkane added the pkgsite label Apr 16, 2024
@gopherbot gopherbot added this to the Unreleased milestone Apr 16, 2024
@seankhliao
Copy link
Member

where is this visual studio code feature documented?

@seankhliao seankhliao added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Apr 16, 2024
@spkane spkane changed the title x/pkgsite: Make it possible to pass in a URL path that all links to directories like static should use. x/pkgsite: Use relative links for static, etc. Apr 17, 2024
@spkane
Copy link
Author

spkane commented Apr 17, 2024

where is this visual studio code feature documented?

@seankhliao I updated the title and description a bit. It looks like this specific issue is directly related to using code-server. A similar problem might also occur with codespaces or openvscode-server, but I am not sure about that.

It looks like this feature is where the issue is manifesting itself.

https://coder.com/docs/code-server/latest/guide#stripping-proxyport-from-the-request-path


Stripping /proxy/<port> from the request path

You may notice that the code-server proxy strips /proxy/<port> from the request path.

HTTP servers should use relative URLs to avoid the need to be coupled to the absolute path at which they are served. This means you must use trailing slashes on all paths with subpaths.

This reasoning is why the default behavior is to strip /proxy/<port> from the base path. If your application uses relative URLs and does not assume the absolute path at which it is being served, it will just work no matter what port you decide to serve it off or if you put it in behind code-server or any other proxy.

However, some prefer the cleaner aesthetic of no trailing slashes. Omitting the trailing slashes couples you to the base path, since you cannot use relative redirects correctly anymore. If you're okay with this tradeoff, use /absproxy instead and the path will be passed as is (e.g., /absproxy/3000/my-app-path).

@seankhliao
Copy link
Member

sounds like you should just use /absproxy?

@spkane
Copy link
Author

spkane commented Apr 17, 2024

sounds like you should just use /absproxy?

No, that makes no difference. I am pretty sure that only prevents code-server from altering the request and stripping the proxy path.

I think the issue here is that pkgsite is not using relative paths.

e.g. https://github.com/golang/pkgsite/blob/6631f5443b15cc3c38d20c33131ac82c8e192ef7/static/frontend/frontend.tmpl#L56

CleanShot 2024-04-17 at 12 10 44

This path won't work since it is really at /proxy/8080/static/ and /absproxy/8080/static/

@spkane
Copy link
Author

spkane commented Apr 17, 2024

cc/ @jmcshane

@seankhliao seankhliao added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. and removed WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. labels Apr 17, 2024
@findleyr findleyr changed the title x/pkgsite: Use relative links for static, etc. x/pkgsite/cmd/pkgsite: Use relative links for static, etc. Apr 25, 2024
@findleyr
Copy link
Contributor

CC @matloob

@findleyr findleyr modified the milestones: Unreleased, pkgsite/backlog Apr 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. pkgsite
Projects
None yet
Development

No branches or pull requests

4 participants