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

refactor: routing #119

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft

refactor: routing #119

wants to merge 3 commits into from

Conversation

sunsetkookaburra
Copy link
Member

No description provided.

@sebasptsch
Copy link

sebasptsch commented Sep 3, 2024

todo: use hono or something

@TianLangHin
Copy link

Hello, I've done a first attempt at using Hono for routing, and also have attempted to take this chance to deal with the trailing slash problem.
Now, http://localhost:1989/client will redirect to http://localhost:1989/client/, and appending more trailing slashes will result in 404.

Additionally, I had run into an issue during testing, which although is unlikely to happen in practice, I believe is worth mentioning and also has a fix.
There came a point where my browser would automatically try to append trailing slashes to requests that already had one, resulting in the judging functionality failing (i.e., it would request http://localhost:1989/comp/prob/:id/judge//, which 404'd). In such cases, clearing the cache of the browser resolved this issue completely.

(Another small thing I wanted to mention was that for my PC's version of Deno, v2.1.4, the sqlite in deps.ts would need to be upgraded to v3.9.1 to work correctly, but I have not committed this change yet, since this might not be the same for the platform we ultimately host ProgComp on.)

Please let me know if there's anything I can improve/fix in my commit, and if it also works as intended on your platforms too. Thanks!

@sunsetkookaburra
Copy link
Member Author

The trailing slash issue is because of permanent redirects (301) that Hono uses.

I think we should leave off trailing slashes on the API, they tend to work better when serving authored HTML content. Where they are used (stripped index.html for clients), they must only be enforced with 302 (non-permanent) instead of 301. Annoyingly, Hono does not allow for easy configuration of this so we'll require a semi-DIY solution.

The other thing that needs to change is mixing and matching trailing slashes for the 'same' path. /team and /team/ really should be the same route (my preference being the trailing slash is stripped). For my 'magical listing' with a trailing slash, a /team/* route is a far better approach.

Wrt Sqlite, if it needs to be updated then go ahead (if you're fussed, then in an individual build(deps): ... commit). JS runtimes, as with browsers, tend to go with the rolling release approach so you can assume that the code will be running on the most recent version (within reason e.g. major breaking changes, etc).

Thanks for getting to this though. I really ought to sit down and consolidate the design now that I can pour over the original work with some distance now that it's been a so long since we built it.

@sunsetkookaburra
Copy link
Member Author

You'll probably also want to rebase on main to avoid the current conflicts.

@TianLangHin
Copy link

Thanks for the information, Oli, I did not realise it was the 301s causing the problem. I have implemented a custom middleware to do the same thing as appendTrailingSlash with the difference of using a 302 instead. As a result, the GET request entries in the main Hono app routing still have trailing slashes on them in the code.

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.

3 participants