2024-01-28 00:46:19 -08:00
|
|
|
import logging
|
|
|
|
|
from wsgiref.simple_server import make_server
|
2024-03-26 00:53:21 -07:00
|
|
|
|
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():
|
2024-03-26 00:53:21 -07:00
|
|
|
config = Configurator(settings={"sqlalchemy.url": db.url, "jinja2.directories": "ttfrog.assets:templates/"})
|
|
|
|
|
config.include("pyramid_tm")
|
|
|
|
|
config.include("pyramid_sqlalchemy")
|
|
|
|
|
config.include("pyramid_jinja2")
|
|
|
|
|
config.add_static_view(name="/static", path="ttfrog.assets:static/")
|
|
|
|
|
config.add_jinja2_renderer(".html", settings_prefix="jinja2.")
|
2024-01-31 22:39:54 -08:00
|
|
|
|
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)
|
2024-03-26 00:53:21 -07:00
|
|
|
config.scan("ttfrog.webserver.views")
|
2024-01-30 01:25:02 -08:00
|
|
|
make_server(host, int(port), config.make_wsgi_app()).serve_forever()
|