serve frontend
This commit is contained in:
parent
6be061ba04
commit
ae818f6a9a
19
README.md
Normal file
19
README.md
Normal 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!
|
|
@ -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))
|
||||||
|
|
Loading…
Reference in a new issue