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

Pattern for avoiding accidental URL over-rides #1520

Open
simonw opened this issue Nov 19, 2021 · 1 comment
Open

Pattern for avoiding accidental URL over-rides #1520

simonw opened this issue Nov 19, 2021 · 1 comment

Comments

@simonw
Copy link
Owner

simonw commented Nov 19, 2021

Following #1517 I'm experimenting with a plugin that does this:

@hookimpl
def register_routes():
    return [
        (r"/(?P<db_name>[^/]+)/(?P<table_and_format>[^/]+?)$", Table().view),
    ]

This is supposed to replace the default table page with new code... but there's a problem: /-/versions on that instance now returns 404 Database '-' does not exist!

Need to figure out a pattern to avoid that happening. Plugins get to add their routes before Datasette's default routes, which is why this is happening here.

@simonw
Copy link
Owner Author

simonw commented Nov 19, 2021

The solution that jumps to mind first is that it would be neat if routes could return something that meant "actually my bad, I can't handle this after all - move to the next one in the list".

A related idea: it might be useful for custom views like my one here to say "no actually call the default view for this, but give me back the response so I can modify it in some way". Kind of like Django or ASGI middleware.

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

No branches or pull requests

1 participant