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

Handle requests without file extension #794

Merged

Conversation

lovasoa
Copy link
Collaborator

@lovasoa lovasoa commented Jan 27, 2025

replaces #786

src/webserver/routing.rs Outdated Show resolved Hide resolved
src/webserver/routing.rs Outdated Show resolved Hide resolved
src/webserver/routing.rs Outdated Show resolved Hide resolved
@lovasoa
Copy link
Collaborator Author

lovasoa commented Jan 27, 2025

@guspower , I made a few comments

…t on file_cache and filesystem, rename ExecutionStore -> FileStore as now checks both assets and sql files. *Very very rough* first implementation pass in http::main_handler. All tests pass.
@guspower
Copy link
Contributor

@lovasoa very very rough first pass at integrating into main_handler. Comment most welcome. The changes to filesystem are too minimal and I need to better understand and integrate safe_local_path for existence checking.

serve_fallback(&mut service_request, e).await?
let app_state: &web::Data<AppState> = service_request.app_data().expect("app_state");
let store = AppFileStore::new(&app_state.sql_file_cache, &app_state.file_system);
let path_and_query = service_request.uri().path_and_query().expect("expected valid path with query from request");
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

we don't want to crash the app here in any case; would be nice to avoid expect.

src/webserver/http.rs Show resolved Hide resolved
@lovasoa lovasoa merged commit 5d81049 into sqlpage:main Feb 3, 2025
8 of 10 checks passed
@lovasoa
Copy link
Collaborator Author

lovasoa commented Feb 3, 2025

Thanks a lot @guspower ! I made the required changes and merged. Feel free to open a follow-up PR if you notice I forgot something :)

@guspower
Copy link
Contributor

guspower commented Feb 3, 2025

Ah excellent. I'll sync and take a look. w00t! :)

@guspower
Copy link
Contributor

guspower commented Feb 3, 2025

Yep cool. Works well. The only outstanding item on my list was whether we should be returning a 404 status code for user-supplied 404 pages?

@lovasoa
Copy link
Collaborator Author

lovasoa commented Feb 3, 2025

I think that would indeed be a nice thing. I didn't add it yesterday because the changes were large already, and that wasn't the behavior of the previous version.

What do you think ? On one hand, people may already have apps that rely on 404.sql for normal pages with non-file-based URLs. On the other hand, people may already be using it to create custom error pages that should have a 404 status code and currently don't.

In any case, we should avoid overriding the status code if the user sets it from their sql code (maybe use RequestContext for that).

@guspower
Copy link
Contributor

guspower commented Feb 3, 2025

Yeah I realized there are two different requirements here (I think, maybe more!):

  1. Serve up custom "default"/"fallback" pages should the path not have a corresponding file, with status code of 200 (i.e. it's intended behaviour)
  2. Serve up actual custom 404 pages with a 404 status code (i.e. it's really not found)

A few possible ways of dealing with it:

  • extend shell to take a status code (i.e. configure the shell to return 404)
  • support defaulting with both a 404.sql and a 200.sql (or fallback.sql or some such)
  • ignore it :)

It would be really useful to know what people are using the 404.sql for!

@lovasoa
Copy link
Collaborator Author

lovasoa commented Feb 3, 2025

extend shell to take a status code (i.e. configure the shell to return 404)

We already have a status_code component for this.

support defaulting with both a 404.sql and a 200.sql (or fallback.sql or some such)

I think that's overkill. One can use status_code to switch between the behaviors. The only question is what should be the default one.


Another interesting followup would be the ability to configure custom routes,
like "/products/{category}/{id}" : "/product.sql"

@guspower
Copy link
Contributor

guspower commented Feb 3, 2025

Ah yes, custom routes, that was the whole reason I brought this up in the first place lol. Thanks for reminding me :)

I'm traveling for the next couple of days but would like to have a go at a candidate implementation for that later on this week - does that work for you? Will create a new fork.

@lovasoa
Copy link
Collaborator Author

lovasoa commented Feb 3, 2025

Great! And if you could check "allow edits by maintainers" in your PR, that would be great!

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.

2 participants