serve frontend

master
Thomas L 2020-06-20 14:32:06 +02:00
parent 6be061ba04
commit ae818f6a9a
2 changed files with 35 additions and 2 deletions

19
README.md Normal file
View File

@ -0,0 +1,19 @@
# Pizzatool
```
# create virtualenv
virtualenv-3 venv
# activate virtualenv
. venv/bin/activate
# install pizzatool
pip install .
# run pizzatool with frontend in frontend/<myfrontend>/dist
pizzatool frontend/<myfrontend>/dist
```
# Frontend Showdown
For the showdown create your frontend somewhere in `frontend/<myfrontend>`.
Running `pizzatool frontend/<myfrontend>/dist` will serve
`frontend/<myfrontend>/dist` at `http://localhost:8000/` and the REST API at
`http://localhost:8000/api`. You can inspect and test the API in
`http://localhost:8000/api/docs`.
Happy Hacking!

View File

@ -1,10 +1,24 @@
from asyncio import run as asyncio_run
from fastapi.staticfiles import StaticFiles
from fastapi import FastAPI
from hypercorn.config import Config
from hypercorn.asyncio import serve
from logging import basicConfig, DEBUG
from pizzatool.api import app
from pizzatool.api import app as api
from sys import argv
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
def main():
basicConfig(level=DEBUG, format="%(levelname)s %(name)s %(message)s")
asyncio_run(serve(app, Config()))
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))