generated from hjess/PythonTemplateProject
[main] Static folder
All checks were successful
Build, Push, and Deploy to Nomad / docker-nomad (push) Successful in 33s
All checks were successful
Build, Push, and Deploy to Nomad / docker-nomad (push) Successful in 33s
This commit is contained in:
15
app.py
15
app.py
@@ -11,25 +11,12 @@ from starlette.middleware.base import BaseHTTPMiddleware
|
||||
from starlette.requests import Request
|
||||
from fastapi.middleware.trustedhost import TrustedHostMiddleware
|
||||
|
||||
class ProxyHeadersMiddleware(BaseHTTPMiddleware):
|
||||
async def dispatch(self, request: Request, call_next):
|
||||
proto = request.headers.get("X-Forwarded-Proto", "http")
|
||||
host = request.headers.get("X-Forwarded-Host", request.headers.get("Host"))
|
||||
|
||||
# Update request scheme and host for correct URL generation
|
||||
request.scope["scheme"] = proto
|
||||
if host:
|
||||
request.scope["server"] = (host.split(":")[0], request.scope["server"][1])
|
||||
|
||||
response = await call_next(request)
|
||||
return response
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
# Mount static files
|
||||
app.mount("/static", StaticFiles(directory="static"), name="static")
|
||||
app.add_middleware(ProxyHeadersMiddleware)
|
||||
app.add_middleware(TrustedHostMiddleware, allowed_hosts=["lifefaq.nomad.i80.dk", "lifefaq.i80.dk","localhost"])
|
||||
|
||||
|
||||
# Templates directory
|
||||
templates = Jinja2Templates(directory="templates")
|
||||
|
||||
Reference in New Issue
Block a user