Open mmzeynalli opened 1 year ago
Hey, not sure if I get your question right. I can think of two points:
Admin(base_url=...)
to configure the URL.Generally I think this makes sense since you want to handle multiple API versionings in your app, running at the same time so setting the version on the whole app might not be a good idea.
Default base_url suits me, however, whenever set any root_path, admin gets messy like I showed in screenshots. You second point would work, but, it is hassle to add api/v1/
to every app's router. I think admin should be independent of root_path and have its url.
Anyway if you want to do that you can just modify admin.app which is just another FastAPI app so you can do any config you want.
How? Just adding root_path breaks admin panel. Is it expected?
I haven't tested this before, doesn't setting this work?
admin.app["root_path"] = ...
Just checked, no it does not work. Change the line to:
admin.app.root_path = ""
, but as app
passed to admin is the global fastapi app, I am overriding global root_path => All endpoints are without /api/v1/
@mmzeynalli have you solved this problem?
To be honest no, unfortunately, have been super busy for the last couple of months.
A workaround I found is to use a middleware:
@app.middleware("http")
async def fix_admin_root_path(request, call_next):
if request.url.path.startswith("/admin/"):
request.scope["path"] = app.root_path + request.url.path
return await call_next(request)
@aminalaee I set root_path="/api/v1" Admin page works in /api/v1/admin and normal. But when i use ajax_lookup in admin, ajax_lookup made request http://localhost:8070/admin/user/ajax/lookup?name=role&term=a without adding root_path and it give 404 Not Found
The problem is in here https://github.com/aminalaee/sqladmin/blob/main/sqladmin/application.py#L226? Can u add root_path before base_url? @aminalaee
@logicli0n Sure. Are you setting root path with admin.app.root_path ? Or on your main app?
@aminalaee I'm setting root path on my main app(in Fastapi).
Did u fix @aminalaee?
Checklist
master
.Describe the bug
I have multiple endpoints and admin panel. I want my endpoints to be in root path of
/api/v1/
, but admin to be just/admin/
. So, I addedapp_configs["root_path"] = f"/api/v{settings.APP_VERSION}"
, and admin panel breaks down.Steps to reproduce the bug
Commenting out second line fixes admin, however, it does not give desired output.
Expected behavior
APIs will have
/api/v1/
prefix, but, admin will not. Admin will load without a problem.Actual behavior
Admin breaks down completely:
and
Links are also broken: In the first image, when you click one of the models it goes to: /api/v1/admin/model/list
Debugging material
No response
Environment
Windows, Python 3.10, Dockerized Fastapi sqladmin version 0.12.0
Additional context
No response