pizzatool/pizzatool/__init__.py

25 lines
854 B
Python
Raw Normal View History

2020-06-18 02:55:56 +00:00
from asyncio import run as asyncio_run
2020-06-20 12:32:06 +00:00
from fastapi.staticfiles import StaticFiles
from fastapi import FastAPI
2020-06-18 02:55:56 +00:00
from hypercorn.config import Config
from hypercorn.asyncio import serve
from logging import basicConfig, DEBUG
2020-06-20 12:32:06 +00:00
from pizzatool.api import app as api
from sys import argv
2020-06-18 02:55:56 +00:00
2020-06-20 12:32:06 +00:00
class SinglePageApplication(StaticFiles):
async def get_response(self, path, scope):
response = await super().get_response(path, scope)
if response.status_code == 404:
response = await super().get_response('.', scope)
return response
2020-06-18 02:55:56 +00:00
def main():
basicConfig(level=DEBUG, format="%(levelname)s %(name)s %(message)s")
2020-06-20 12:32:06 +00:00
app = FastAPI()
config = Config()
config.accesslog = '-'
app.mount('/api', app=api)
app.mount('/', app=SinglePageApplication(directory=argv[1], html=True))
asyncio_run(serve(app, config))