mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
Refactored everything into a factory function
I now call a factory function to construct the Sanic app:
app = app_factory(files)
This allows me to pass additional arguments to it, e.g. the files to serve.
Also refactored my class-based views to accept jinja as an argument, e.g:
app.add_route(
TableView.as_view(jinja),
'/<db_name:[^/]+>/<table:[^/]+?><as_json:(.jsono?)?$>'
)
This commit is contained in:
parent
0ac8bbce2e
commit
1fc75809a6
2 changed files with 61 additions and 41 deletions
|
|
@ -1,6 +1,6 @@
|
|||
import click
|
||||
from click_default_group import DefaultGroup
|
||||
from .app import app, ensure_build_metadata
|
||||
from .app import app_factory, ensure_build_metadata
|
||||
|
||||
|
||||
@click.group(cls=DefaultGroup, default='serve', default_if_no_args=True)
|
||||
|
|
@ -23,4 +23,5 @@ def build():
|
|||
def serve(files, host, port, debug):
|
||||
"""Serve up specified database files with a web UI"""
|
||||
click.echo('Serve! files={} on port {}'.format(files, port))
|
||||
app = app_factory(files)
|
||||
app.run(host=host, port=port, debug=debug)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue