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

Custom URL routing with independent tests #306

Closed
simonw opened this issue Jun 5, 2018 · 5 comments
Closed

Custom URL routing with independent tests #306

simonw opened this issue Jun 5, 2018 · 5 comments

Comments

@simonw
Copy link
Owner

simonw commented Jun 5, 2018

The more I think about #303 the more I feel that Datasette's URL routing needs go beyond Django-style regex matching.

If we go custom, tests should live in test_routing.py

@simonw
Copy link
Owner Author

simonw commented Jun 5, 2018

Input:

  • function that says if a name is a valid database
  • Function that says if a table exists
  • URL

Output:

  • view class
  • Arguments
  • Redirect (if it should redirect)

@simonw
Copy link
Owner Author

simonw commented Jun 5, 2018

I'm going to use a named tuple for the output. That way I can support either tuple destructing or explicit property access on the returned value.

@simonw
Copy link
Owner Author

simonw commented Jun 5, 2018

To support a future where Datasette is an ASGI app that can be attached to a URL within a larger application the routing function should have the option to accept a path prefix which will then be automatically attached to any resulting redirects.

@simonw
Copy link
Owner Author

simonw commented Jun 5, 2018

A neat trick could be that if the router returns a redirect it could then resolve that redirect to see if it will 404 (or redirect itself) before returning that response.

This would need its own counter to guard against infinite redirects.

I'm not going to do this though: any view that results in a chain of redirects like this is a bug that should be fixed at the source.

@simonw
Copy link
Owner Author

simonw commented Jun 7, 2018

I started sketching this out in a branch, see pull request #307 - but I've decided I don't like it. I'm going to close this ticket and stick with regular expression URL routing for the moment. If I change my mind in the future the code in #307 lives in separate files (datasette/routes.py and tests/test_routes.py) so bringing it back into the project will be trivial.

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

No branches or pull requests

1 participant