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

Let register_routes() over-ride default routes within Datasette #1517

Closed
simonw opened this issue Nov 19, 2021 · 2 comments
Closed

Let register_routes() over-ride default routes within Datasette #1517

simonw opened this issue Nov 19, 2021 · 2 comments
Labels
Milestone

Comments

@simonw
Copy link
Owner

simonw commented Nov 19, 2021

See #878 (comment)_ - right now register_routes() can't replace default Datasette routes.

It would be neat if plugins could do this - especially if there was a neat documented way for them to then re-dispatch to the original route code after making some kind of modification.

@simonw
Copy link
Owner Author

simonw commented Nov 19, 2021

I made a mistake: I just wrote a test that proves that plugins CAN over-ride default routes, plus if you look at the code here the plugins get to register themselves first:

datasette/datasette/app.py

Lines 965 to 981 in 0156c6b

def app(self):
"""Returns an ASGI app function that serves the whole of Datasette"""
routes = []
for routes_to_add in pm.hook.register_routes(datasette=self):
for regex, view_fn in routes_to_add:
routes.append((regex, wrap_view(view_fn, self)))
def add_route(view, regex):
routes.append((regex, view))
# Generate a regex snippet to match all registered renderer file extensions
renderer_regex = "|".join(r"\." + key for key in self.renderers.keys())
add_route(IndexView.as_view(self), r"/(?P<as_format>(\.jsono?)?$)")
# TODO: /favicon.ico and /-/static/ deserve far-future cache expires
add_route(favicon, "/favicon.ico")

@simonw
Copy link
Owner Author

simonw commented Nov 19, 2021

Confirmed - my test plugin is indeed correctly over-riding the table page.

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

No branches or pull requests

1 participant