mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
Added asgi_wrapper plugin hook, closes #520
This commit is contained in:
parent
16f0ef9054
commit
a253173008
5 changed files with 78 additions and 1 deletions
|
|
@ -651,9 +651,12 @@ class Datasette:
|
|||
if not database.is_mutable:
|
||||
await database.table_counts(limit=60 * 60 * 1000)
|
||||
|
||||
return AsgiLifespan(
|
||||
asgi = AsgiLifespan(
|
||||
AsgiTracer(DatasetteRouter(self, routes)), on_startup=setup_db
|
||||
)
|
||||
for wrapper in pm.hook.asgi_wrapper(datasette=self):
|
||||
asgi = wrapper(asgi)
|
||||
return asgi
|
||||
|
||||
|
||||
class DatasetteRouter(AsgiRouter):
|
||||
|
|
|
|||
|
|
@ -5,6 +5,11 @@ hookspec = HookspecMarker("datasette")
|
|||
hookimpl = HookimplMarker("datasette")
|
||||
|
||||
|
||||
@hookspec
|
||||
def asgi_wrapper(datasette):
|
||||
"Returns an ASGI middleware callable to wrap our ASGI application with"
|
||||
|
||||
|
||||
@hookspec
|
||||
def prepare_connection(conn):
|
||||
"Modify SQLite connection in some way e.g. register custom SQL functions"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue