tabletop-frog/ttfrog/webserver/application.py

30 lines
918 B
Python
Raw Normal View History

2024-01-28 00:46:19 -08:00
import logging
from wsgiref.simple_server import make_server
2024-01-30 01:25:02 -08:00
from pyramid.config import Configurator
2024-01-28 00:46:19 -08:00
2024-01-30 01:25:02 -08:00
from ttfrog.db.manager import db
from ttfrog.webserver.routes import routes
2024-01-28 00:46:19 -08:00
2024-01-30 01:25:02 -08:00
def configuration():
config = Configurator(settings={
2024-01-28 00:46:19 -08:00
'sqlalchemy.url': db.url,
2024-01-31 22:39:54 -08:00
'jinja2.directories': 'ttfrog.assets:templates/'
2024-01-28 00:46:19 -08:00
})
2024-01-30 01:25:02 -08:00
config.include('pyramid_tm')
config.include('pyramid_sqlalchemy')
2024-01-31 22:39:54 -08:00
config.include('pyramid_jinja2')
config.add_static_view(name='/static', path='ttfrog.assets:static/')
config.add_jinja2_renderer('.html', settings_prefix='jinja2.')
2024-01-30 01:25:02 -08:00
return config
2024-01-28 00:46:19 -08:00
def start(host: str, port: int, debug: bool = False) -> None:
logging.debug(f"Configuring webserver with {host=}, {port=}, {debug=}")
2024-01-30 01:25:02 -08:00
config = configuration()
config.include(routes)
config.scan('ttfrog.webserver.views')
make_server(host, int(port), config.make_wsgi_app()).serve_forever()