Upload front_end.py
Browse files- front_end.py +30 -0
front_end.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import uvicorn
|
| 2 |
+
from fastapi import FastAPI, Request
|
| 3 |
+
from fastapi.staticfiles import StaticFiles
|
| 4 |
+
from fastapi.templating import Jinja2Templates
|
| 5 |
+
from fastapi.responses import HTMLResponse
|
| 6 |
+
from fastapi.middleware.cors import CORSMiddleware
|
| 7 |
+
|
| 8 |
+
app = FastAPI()
|
| 9 |
+
|
| 10 |
+
app.add_middleware(
|
| 11 |
+
CORSMiddleware,
|
| 12 |
+
# Replace ["*"] with the appropriate list of allowed origins
|
| 13 |
+
allow_origins=["*"],
|
| 14 |
+
allow_credentials=True,
|
| 15 |
+
allow_methods=["*"],
|
| 16 |
+
allow_headers=["*"],
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
app.mount("/static", StaticFiles(directory="static", html=True), name="static")
|
| 20 |
+
templates = Jinja2Templates(directory="static")
|
| 21 |
+
|
| 22 |
+
@app.get("/{path_name:path}", response_class=HTMLResponse, tags=["Frontend"])
|
| 23 |
+
async def catch_all(request: Request, path_name: str):
|
| 24 |
+
return templates.TemplateResponse("index.html", {"request": request})
|
| 25 |
+
|
| 26 |
+
if __name__ == "__main__":
|
| 27 |
+
# uvicorn.run("front_end:app", host="0.0.0.0", port=443, reload=False)
|
| 28 |
+
uvicorn.run("front_end:app", host="0.0.0.0", port=443, reload=False,
|
| 29 |
+
ssl_keyfile="ssl/private.pem",
|
| 30 |
+
ssl_certfile="ssl/certificate.crt")
|