mongkok / fastapi-debug-toolbar

A debug toolbar for FastAPI.
https://fastapi-debug-toolbar.domake.io
BSD 3-Clause "New" or "Revised" License
140 stars 14 forks source link

线上环境无法正常使用 #9

Closed lenkyes closed 1 year ago

lenkyes commented 2 years ago

你好,同样一套代码我在本地使用没有问题,线上环境就无法正常使用了,直接位置跑到了左下了,而且无法加载出来。 本地正常图: 线上无法使用图:

mongkok commented 1 year ago

Hey @lenkyes , this package uses the Request.url_for method to generate absolute URLs (not relative URLs).

As I see your issue seems to be related to the static files, use uvicorn --proxy-headers option as described here https://github.com/encode/starlette/issues/538#issuecomment-518748568.

It may be useful to add a new settings related to this:

from debug_toolbar.middleware import DebugToolbarMiddleware
from fastapi import FastAPI

app = FastAPI(debug=True)

app.add_middleware(
    DebugToolbarMiddleware,
    # request.url_for by default
    url_for=lambda request: request.app.url_path_for,
)

.. so we can easily select between absolute or relative urls.