Skip to content

Conversation

@schloerke
Copy link
Collaborator

@schloerke schloerke commented Sep 29, 2022

A different solution to #881

Situation:

  • Static handler is mounted at /;
  • Route /b/z is mounted at /a
  • Route /c is mounted at /a/b

Goal: Request /a/b/c

Current behavior:

  • The route of /a/b/c matches against mount location of /.
  • The static file handler attempts to handle /a/b/c.
    • No file is found, a 404 is returned.

New behavior:

  • The route of /a/b/c matches against mount location of /.
  • The static file handler attempts to handle /a/b/c
    • No file is found, route is forwarded
    • Mount's $route() is marked as routeNotFound()
  • The route of /a/b/c matches against mount location /a
    • The route is trimmed to /b/c
    • The route /b/c does not match any routes
    • Mount's $route() is marked as routeNotFound()
  • The route of /a/b/c matches against mount location /a/b
    • The route is trimmed to /c
    • The route /c matches route location /c
    • Result of /c is returned

This would allow for #882 to not be merged, keep the docs as the last mount location. This benefits the user in that their content will always have preference over anything mounted in /__docs__/

PR task list:

  • Should this behavior be opt in? Opt out?
  • How should the user opt in / out?
    • $set_fallback(fallback = TRUE)?
    • $mount(path, router, fallback = TRUE)?
  • Append mounted router, do not overwrite existing router
  • Update NEWS
  • Add tests
  • Update documentation with devtools::document()

@schloerke schloerke requested a review from jcheng5 September 29, 2022 13:53
@jcheng5
Copy link
Member

jcheng5 commented Sep 29, 2022

I suggest removing the IS_MOUNT tracking variable (tricky to make this work with async responses anyway) and instead have the route() method (which is recursive) never do 404 handling; instead, leave that to serve() (which is not recursive).

@jcheng5 jcheng5 mentioned this pull request Oct 5, 2022
3 tasks
@jcheng5
Copy link
Member

jcheng5 commented Oct 6, 2022

As written, you can choose to either have 1) 405 and missing-trailing-slash automatically handled for you, or 2) a custom top-level 404 handler, but you cannot have both.

…ound.

In `$serve()`, move `routeNotFoundStep` before `postRouteStep`
In `$route()`, if `404` handler has been set, call `lastChanceRouteNotFound()`
@schloerke
Copy link
Collaborator Author

Going to wait on this PR for a bit as the changes are fairly drastic compared to current functionality

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