Skip to content
This repository has been archived by the owner on Oct 28, 2024. It is now read-only.

Discussion: obviate need for duplicate route prefix #39

Closed
itowlson opened this issue Jul 16, 2021 · 4 comments
Closed

Discussion: obviate need for duplicate route prefix #39

itowlson opened this issue Jul 16, 2021 · 4 comments

Comments

@itowlson
Copy link
Contributor

Consider the following handler:

[[handler]]
route = "/images/..."
external.bindleId = "fileserver/0.3.0"
external.handlerId = "static"
files = ["images/*.jpg"]

Because the linked files have the prefix images, and are served from the /images URL, they need to be addressed as http://.../images/images/cassowary.jpg. This is surprising; and vexing, because when the dev is testing against their local filesystem, the files won't have the double prefix.

We should consider options for making this less surprising and less vexing, ideally "intelligently" (that is, without requiring the developer to specify their desired behaviour) while still predictably. We may also need to support an override for when our intelligent behaviour turns out to be stupid after all.

Currently I am thinking of the rule:

  • If you are in a wildcard route, and any prefix of a files pattern matches the route prefix, then that prefix is dropped.

This works nicely for typical static file serving cases. However I would like to talk more about possible other cases where this might break down, or is surprising. For example, what would you expect to happen here"

[[handler]]
route = "/images/..."
files = ["images/*.jpg", "photos/*.jpg"]

What about scenarios other than static file serving?

@technosophos
Copy link
Contributor

I am not sure I follow "if the developer is testing against their local filesystem". How are they testing locally such that the URL would resolve? We had talked about the hippofactory --prepare ... && wagi --standalone-bindle thing, but that would definitely resolve the path correctly.

@itowlson
Copy link
Contributor Author

I was thinking about native debug situations (since Wasm debugging remains not great). But yeah, maybe that consideration is irrelevant.

Nevertheless, it still feels like writing /images/images/foo.jpg in your HTML when there is no images/images path anywhere in the project structure feels gesticulates vaguely wrong, at least to me...

@technosophos
Copy link
Contributor

Probably a generic path rewriting, perhaps via regexp, would be the most flexible. See, for example, mod_rewrite for an example of how Apache dealt with this, or the rewrite directive in nginx, which looks like this:

rewrite regexp replacement [flags]

@bacongobbler
Copy link
Contributor

no longer relevant after merging #121.

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

No branches or pull requests

3 participants