-
Notifications
You must be signed in to change notification settings - Fork 335
/
Copy path__init__.py
56 lines (42 loc) · 1.72 KB
/
__init__.py
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from __future__ import annotations as _annotations
import sys
from contextlib import asynccontextmanager
from fastapi import FastAPI
from fastapi.responses import HTMLResponse, PlainTextResponse
from fastui import prebuilt_html
from fastui.auth import fastapi_auth_exception_handling
from fastui.dev import dev_fastapi_app
from httpx import AsyncClient
from .auth import router as auth_router
from .components_list import router as components_router
from .forms import router as forms_router
from .main import router as main_router
from .sse import router as sse_router
from .tables import router as table_router
@asynccontextmanager
async def lifespan(app_: FastAPI):
async with AsyncClient() as client:
app_.state.httpx_client = client
yield
frontend_reload = '--reload' in sys.argv
if frontend_reload:
# dev_fastapi_app reloads in the browser when the Python source changes
app = dev_fastapi_app(lifespan=lifespan)
else:
app = FastAPI(lifespan=lifespan)
fastapi_auth_exception_handling(app)
app.include_router(components_router, prefix='/api/components')
app.include_router(sse_router, prefix='/api/components')
app.include_router(table_router, prefix='/api/table')
app.include_router(forms_router, prefix='/api/forms')
app.include_router(auth_router, prefix='/api/auth')
app.include_router(main_router, prefix='/api')
@app.get('/robots.txt', response_class=PlainTextResponse)
async def robots_txt() -> str:
return 'User-agent: *\nAllow: /'
@app.get('/favicon.ico', status_code=404, response_class=PlainTextResponse)
async def favicon_ico() -> str:
return 'page not found'
@app.get('/{path:path}')
async def html_landing() -> HTMLResponse:
return HTMLResponse(prebuilt_html(title='FastUI Demo'))