-
Notifications
You must be signed in to change notification settings - Fork 117
Expand file tree
/
Copy path_server.py
More file actions
30 lines (22 loc) · 822 Bytes
/
_server.py
File metadata and controls
30 lines (22 loc) · 822 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import time
from pathlib import Path
import fastapi.responses
import uvicorn
from fastapi import FastAPI
from fastapi.staticfiles import StaticFiles
from starlette import status
from starlette.responses import FileResponse
def run_webserver():
openwb_root = Path(__file__).parents[2]
app = FastAPI()
@app.get("/")
async def root():
return fastapi.responses.RedirectResponse("/web/", status.HTTP_303_SEE_OTHER)
@app.get("/web/")
async def web_root():
return FileResponse(openwb_root.joinpath("web", "themes", "standard", "theme.html"))
@app.get("/sample")
async def sample():
return f"Hello world! Time is {time.time()}"
app.mount("/web", StaticFiles(directory=openwb_root / "web", html=True), name="static")
uvicorn.run(app, host="0.0.0.0", port=80)