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

Update routing #670

Merged
merged 4 commits into from
Jan 26, 2024
Merged

Update routing #670

merged 4 commits into from
Jan 26, 2024

Conversation

CannonLock
Copy link
Contributor

- /path -> 301 Redirect -> /path/index.html if exists
- /path that doesn't exists returns 404
Copy link
Contributor

@haoming29 haoming29 left a comment

Choose a reason for hiding this comment

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

LGTM with two small changes requested

Sorry I meant to hit Changes requested

web_ui/ui.go Outdated
// If path doesn't have extension, is not a directory, and has a index file, redirect to index file
if !strings.Contains(path, ".") && !strings.HasSuffix(path, "/") {
if _, err := webAssets.ReadFile("frontend/out" + path + "/index.html"); err == nil {
ctx.Redirect(http.StatusFound, "/view/"+path+"/")
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be http.StatusMovedPermanently instead. As Go http server did in here

Copy link
Contributor

@haoming29 haoming29 Jan 17, 2024

Choose a reason for hiding this comment

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

I'm actually a bit confused here. I thought we should not redirect user to index.html if their path has / suffix, like /view/login/ but we should append index.html to the user path internally to find the correct file whenever there's only a / ?

For requests without a trailing slash, and is not a file name, like /view/login, we want to permanently redirect them to /view/login/.

For requests with a valid file name (that webAssets.ReadFile gives a positive answer), we can serve the file directly.

This way, the path is cleaner and more readable for users but we are still able to serve *index.html file which won't hurt SEO.

Copy link
Contributor

Choose a reason for hiding this comment

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

Plus, for the path parameter, we might want to clean it first to prevent directory traversal attack:

safePath := path.Clean("/" + pathParam)

web_ui/ui.go Outdated Show resolved Hide resolved
@haoming29 haoming29 self-requested a review January 17, 2024 23:20
@haoming29
Copy link
Contributor

LGTM with the latest commit. I fixed a format issue and reordered the "direct-to-single-server" logic so that when visiting registry from / we can be directed to registry page instead of login page. Waiting for tests to pass before merging.

@haoming29 haoming29 merged commit 94ae6e9 into PelicanPlatform:main Jan 26, 2024
9 checks passed
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

Successfully merging this pull request may close these issues.

Forward /path to /path/ if /path/index.html exists
2 participants