diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2025-01-27 16:24:33 +0100 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2025-01-27 16:24:33 +0100 |
| commit | 6e3a9c5836aa3bb273529959d84dfae074857c78 (patch) | |
| tree | 51596de780bfa105b02812fefdd3db04550b4c15 /server.py | |
| parent | 550c6ce51c2f95fa0902adc99534fbf11661bb89 (diff) | |
| download | cyberschuessel-6e3a9c5836aa3bb273529959d84dfae074857c78.tar.gz cyberschuessel-6e3a9c5836aa3bb273529959d84dfae074857c78.zip | |
move python code into the project's root
Diffstat (limited to 'server.py')
| -rwxr-xr-x | server.py | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/server.py b/server.py new file mode 100755 index 0000000..ec425f7 --- /dev/null +++ b/server.py @@ -0,0 +1,54 @@ +#!/usr/bin/env python3 +"""aiohttp based webserver running a cyberschuessel app""" +import argparse +import logging +import os + +import jinja2 + +import aiohttp_jinja2 +from aiohttp import web + +from schuessel import Schuessel + + +async def init_app(): + """Create and initialize a new cyberschuessel aiohttp app""" + app = web.Application() + app.on_shutdown.append(shutdown) + + schuessel = Schuessel() + app['schuessel'] = schuessel + + # aiohttp_jinja2.setup(app, + # loader=jinja2.PackageLoader('cyberschuessel', + # 'templates')) + + template_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), + "templates") + + aiohttp_jinja2.setup(app, loader=jinja2.FileSystemLoader(template_path)) + + app.router.add_get('/', schuessel.handler) + + return app + + +async def shutdown(app): + """shutdown a cyberschuessel aiohttp app""" + await app['schuessel'].close_all() + + +def main(args): + """init and run a cyberschuessel aiohttp app""" + logging.basicConfig(level=logging.DEBUG) + + app = init_app() + web.run_app(app, port=args.port) + + +if __name__ == '__main__': + parser = argparse.ArgumentParser(description="aiohttp server example") + parser.add_argument('--port', type=int, default=80) + + main(parser.parse_args()) |
