Set up the bones of a Flask app with configuration

This commit is contained in:
Campbell Alden 2026-07-30 22:45:25 +09:00
parent 0909fd7e99
commit a7fdd6cbd0
7 changed files with 131 additions and 1 deletions

View file

@ -1,3 +1,35 @@
#!/usr/bin/env python
print('hello, world!')
from waitress import serve
from flask import Flask
import argparse
import logging
from src.config import parse_config, DEFAULT_CONFIG, Config
logger = logging.getLogger(__name__)
def create_app(name: str, config: Config) -> Flask:
logging.basicConfig(level=config.logging.level, format=('%(asctime)s %(levelname)s [%(name)s] %(message)s'))
app = Flask(name)
if config.host:
app.config['SERVER_NAME'] = config.host
return app
def main():
parser = argparse.ArgumentParser('Cereal', description='run the Cereal server')
parser.add_argument('--config', '-c', help='The path to the configuration file, expects JSON')
args = parser.parse_args()
config = parse_config(args.config) if args.config else DEFAULT_CONFIG
app = create_app('Cereal', config)
logger.info(str(config))
serve(app, host='0.0.0.0' if config.host is None else config.host, port=config.port)
if __name__ == '__main__':
main()