Skip to content

how to mount two sub app with its own static files? #5850

@phoenixor

Description

@phoenixor

First Check

  • I added a very descriptive title to this issue.
  • I used the GitHub search to find a similar issue and didn't find it.
  • I searched the FastAPI documentation, with the integrated search.
  • I already searched in Google "How to X in FastAPI" and didn't find any information.
  • I already read and followed all the tutorial in the docs and didn't find an answer.
  • I already checked if it is not related to FastAPI but to Pydantic.
  • I already checked if it is not related to FastAPI but to Swagger UI.
  • I already checked if it is not related to FastAPI but to ReDoc.

Commit to Help

  • I commit to help with one of those options 👆

Example Code

from fastapi import FastAPI
from fastapi.staticfiles import StaticFiles

app = FastAPI()
subapp1= FastAPI()
subapp2 = FastAPI()

app.mount("/subapp1", subapp1)
app.mount("/subapp2", subapp2)

subapp1.mount(
    "/assets",
    StaticFiles(directory="app/subapp1/frontend/dist/assets"),
)
subapp2.mount(
    "/assets",
    StaticFiles(directory="app/subapp2/frontend/dist/assets"),
)

@subapp1.get("/")
async def subapp1():
    return FileResponse("app/subapp1/frontend/dist/index.html")
@subapp2.get("/")
async def subapp2():
    return FileResponse("app/subapp2/frontend/dist/index.html")


if __name__ == "__main__":
    import uvicorn
    uvicorn.run("main:app", host="0.0.0.0", port=8080, reload=True)

Description

when calling "http://localhost:8080/subapp1/" and "http://localhost:8080/subapp2/"
only subapp1 success, but subapp2 failed with static files 404

Operating System

Windows

Operating System Details

No response

FastAPI Version

0.88.0

Python Version

3.10.2

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions