307 Temporary Redirect On Specific Routes #386
Replies: 3 comments 5 replies
-
Hey there! I've had some problems with HTTPS and need to override the import jinja2
@jinja2.pass_context # noqa
def url_for(context: dict, name: str, **path_params: Any) -> str:
request = context["request"]
http_url = request.url_for(name, **path_params)
if request.url.scheme == 'https' or "x-forwarded-for" in request.headers.keys():
return str(http_url).replace("http", "https", 1)
else:
return http_url
class HTTPSAdmin(Admin):
def init_templating_engine(self) -> Jinja2Templates:
templates = super().init_templating_engine()
templates.env.globals["url_for"] = url_for
return templates |
Beta Was this translation helpful? Give feedback.
-
I think (most probably) you don't need to change the code if you setup the reverse proxy (Nginx, etc) and Uvicorn + Gunicorn correctly. |
Beta Was this translation helpful? Give feedback.
-
i have same problem. i have nginx as reverse proxy (ssl), but without gunicorn, only uvicron. the first problem was not loading static files on any sqladmin pages. When i open any sqladmin pages i receive admin static files over http and browser blocked this response. i added <meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests"> Looks like strange... |
Beta Was this translation helpful? Give feedback.
-
I have an API service that I wrote with FastApi and served with gunicorn. Apache is working on the server as a reverse proxy and SSL manager.
Everything was fine until I decided to use SqlAdmin as the admin panel.
The problem is that my API endpoints work fine with SSL but SqlAdmin endpoints are not.
e.g: Responses I get when I want to reach https://example.com/admin: (FAIL)
e.g: Responses I get when I want to reach https://example.com/users: (PASS) (API ENDPOINT)
Apache Configuration:
Gunicorn Configuration:
I don't have any idea how this behavior happened at all so any clue would be helpful :)
Thanks in advance.
every request reached to this response on gunicorn:
WARNING: Invalid HTTP request received.
Nothing changed.
Beta Was this translation helpful? Give feedback.
All reactions