mirror of
https://github.com/rommapp/romm.git
synced 2026-06-28 06:46:00 +00:00
fix: Backend URL redirection logic
Fix FastAPI and nginx configuration, to make the application correctly redirect URLs. This is specially useful when URLs ended with forward slash are redirected to their stripped version. Included changes: * Stop removing the `/api` prefix in nginx rewrite rules, so FastAPI knows what's the original URL path being requested. * Use `$http_host` in nginx, so FastAPI receives both the original host and port, to build the redirect URL (as `$host` does not include the port, if present). * Make all FastAPI included routers know their prefix, to correctly route incoming requests. This fix was found based on a report that redirects from URLs ended with forward slash were not working [1]. [1] https://github.com/rommapp/romm/issues/1051#issuecomment-2269049762
This commit is contained in:
@@ -89,22 +89,22 @@ app.add_middleware(
|
||||
# Sets context vars in request-response cycle
|
||||
app.middleware("http")(set_context_middleware)
|
||||
|
||||
app.include_router(heartbeat.router)
|
||||
app.include_router(auth.router)
|
||||
app.include_router(user.router)
|
||||
app.include_router(platform.router)
|
||||
app.include_router(rom.router)
|
||||
app.include_router(search.router)
|
||||
app.include_router(saves.router)
|
||||
app.include_router(states.router)
|
||||
app.include_router(tasks.router)
|
||||
app.include_router(feeds.router)
|
||||
app.include_router(config.router)
|
||||
app.include_router(stats.router)
|
||||
app.include_router(raw.router)
|
||||
app.include_router(screenshots.router)
|
||||
app.include_router(firmware.router)
|
||||
app.include_router(collections.router)
|
||||
app.include_router(heartbeat.router, prefix="/api")
|
||||
app.include_router(auth.router, prefix="/api")
|
||||
app.include_router(user.router, prefix="/api")
|
||||
app.include_router(platform.router, prefix="/api")
|
||||
app.include_router(rom.router, prefix="/api")
|
||||
app.include_router(search.router, prefix="/api")
|
||||
app.include_router(saves.router, prefix="/api")
|
||||
app.include_router(states.router, prefix="/api")
|
||||
app.include_router(tasks.router, prefix="/api")
|
||||
app.include_router(feeds.router, prefix="/api")
|
||||
app.include_router(config.router, prefix="/api")
|
||||
app.include_router(stats.router, prefix="/api")
|
||||
app.include_router(raw.router, prefix="/api")
|
||||
app.include_router(screenshots.router, prefix="/api")
|
||||
app.include_router(firmware.router, prefix="/api")
|
||||
app.include_router(collections.router, prefix="/api")
|
||||
|
||||
app.mount("/ws", socket_handler.socket_app)
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ http {
|
||||
listen 8080;
|
||||
server_name localhost;
|
||||
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header Host $http_host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
@@ -79,7 +79,6 @@ http {
|
||||
|
||||
# Backend api calls
|
||||
location /api {
|
||||
rewrite /api/(.*) /$1 break;
|
||||
proxy_pass http://wsgi_server;
|
||||
}
|
||||
location /ws {
|
||||
|
||||
Reference in New Issue
Block a user