You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.8 KiB
46 lines
1.8 KiB
from fastapi import FastAPI, Request
|
|
from fastapi.responses import HTMLResponse
|
|
from fastapi.staticfiles import StaticFiles
|
|
import uvicorn
|
|
|
|
from classes.constraints import Constraints
|
|
|
|
from starlette.exceptions import HTTPException as StarletteHTTPException
|
|
|
|
app = FastAPI(docs_url=None, redoc_url=None)
|
|
|
|
app.mount('/static', StaticFiles(directory='frontend/static'), name='static')
|
|
|
|
from routers import auth, static, dashboard, db, api
|
|
|
|
app.include_router(auth.router)
|
|
app.include_router(dashboard.router)
|
|
app.include_router(static.router)
|
|
app.include_router(api.router)
|
|
|
|
|
|
@app.get("/")
|
|
@app.get('/root', response_class=HTMLResponse)
|
|
async def root(request: Request):
|
|
return Constraints.templates.TemplateResponse('/root/index.html', {'request': request})
|
|
|
|
|
|
# shitty error handling
|
|
@app.exception_handler(StarletteHTTPException)
|
|
async def http_exception_handler(request, exc):
|
|
if exc.status_code == 404:
|
|
return Constraints.templates.TemplateResponse('/errors/index.html', {'request': request,
|
|
'error': 'not found...',
|
|
'url': '/root'})
|
|
elif exc.status_code == 500:
|
|
return Constraints.templates.TemplateResponse('/errors/index.html', {'request': request,
|
|
'error': 'internal server error',
|
|
'url': '/root'})
|
|
return Constraints.templates.TemplateResponse('/errors/index.html', {'request': request,
|
|
'error': exc.detail,
|
|
'url': '/root'})
|
|
|
|
|
|
if __name__ == '__main__':
|
|
uvicorn.run(app, host='127.0.0.1', port=8080)
|