tabletop-frog/ttfrog/webserver/application.py

25 lines
683 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-30 01:25:02 -08:00
config.include('pyramid_tm')
config.include('pyramid_sqlalchemy')
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()