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

feat: allow dynamic routing based on file paths #55

Merged
merged 8 commits into from
Dec 13, 2022

Conversation

Angelmmiguel
Copy link
Contributor

@Angelmmiguel Angelmmiguel commented Dec 7, 2022

Introduce dynamic routes with parameters in files. For example, [id].wasm or users/[id]/show. The server identifies this pattern in files and configure actix to reply to parametrized URLs.

Note that the same wasm_handler serves all the requests. This means that wws calculates the best worker to reply on every request. The reasons I coded it in that way are:

  • We fully control collisions when two workers can reply to the same request (see the Allow dynamic parameters in URLs #10 for more information). Actix will reply with the first handler that matches. However, users cannot set the handlers manually, so we want to ensure a consistent behavior.
  • To map an actix path with a runner, we need to create factory service. Note that Actix will create an instance per thread (worker), so Runner instances cannot be shared. This will require multiple instances of the same Wasm module, so the resource consumption will be increased.

I updated the Rust and JavaScript kits and introduced some new examples so you can see how parameter in URLs works.

It closes #10

Pending

  • Improve the UI of the JS examples
  • Add a new Rust example
  • Update the documentation

@Angelmmiguel Angelmmiguel added the 🚀 enhancement New feature or request label Dec 7, 2022
@Angelmmiguel Angelmmiguel self-assigned this Dec 7, 2022
@Angelmmiguel Angelmmiguel requested review from ereslibre, assambar and gzurl and removed request for ereslibre December 13, 2022 08:13
@Angelmmiguel Angelmmiguel marked this pull request as ready for review December 13, 2022 08:13
Copy link
Contributor

@ereslibre ereslibre left a comment

Choose a reason for hiding this comment

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

Super cool feature and work! I have some comments regarding compatibility mainly with Windows, and other minor comments.

All in all, I think despite surprising to have brackets at the filesystem level, it is a useful feature when developing locally and prioritizing fast results.

docs/docs/features/dynamic-routes.md Outdated Show resolved Hide resolved
docs/docs/features/dynamic-routes.md Outdated Show resolved Hide resolved
docs/docs/features/dynamic-routes.md Show resolved Hide resolved
docs/docs/features/static-assets.md Outdated Show resolved Hide resolved
docs/docs/tutorials/rust-workers.md Outdated Show resolved Hide resolved
src/router.rs Outdated Show resolved Hide resolved
src/router.rs Outdated Show resolved Hide resolved
src/router.rs Outdated Show resolved Hide resolved
src/router.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@ereslibre ereslibre left a comment

Choose a reason for hiding this comment

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

🚢 it!

@Angelmmiguel Angelmmiguel merged commit f96d544 into main Dec 13, 2022
// Default content type
builder.insert_header(("Content-Type", "text/html"));

for (key, val) in handler_result.headers.iter() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is iter() really needed? I think the preferred style is using a reference instead of explicit .iter():
https://rust-lang.github.io/rust-clippy/master/index.html#explicit_iter_loop.

Suggested change
for (key, val) in handler_result.headers.iter() {
for (key, val) in &handler_result.headers {

@Angelmmiguel Angelmmiguel deleted the 10-dynamic-routes branch May 8, 2023 12:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow dynamic parameters in URLs
4 participants