Compare commits

...

2 commits

Author SHA1 Message Date
v ae818f6a9a serve frontend 2020-06-20 14:32:06 +02:00
v 6be061ba04 pin ormantic to version with bugfix 2020-06-20 14:31:45 +02:00
3 changed files with 37 additions and 3 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 asyncio import run as asyncio_run
from fastapi.staticfiles import StaticFiles
from fastapi import FastAPI
from hypercorn.config import Config from hypercorn.config import Config
from hypercorn.asyncio import serve from hypercorn.asyncio import serve
from logging import basicConfig, DEBUG 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(): def main():
basicConfig(level=DEBUG, format="%(levelname)s %(name)s %(message)s") 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))

View file

@ -13,9 +13,10 @@ setup(
] ]
}, },
install_requires=[ install_requires=[
'aiofiles',
'aiosqlite', 'aiosqlite',
'fastapi', 'fastapi',
'hypercorn', 'hypercorn',
'ormantic @ https://github.com/MushroomMaula/ormantic/tarball/master#egg=ormantic-0.0.32', 'ormantic @ https://github.com/dl6tom/ormantic/tarball/bugfix__get_key_factory#egg=ormantic-0.0.32',
] ]
) )