我有一个 React 应用,我正尝试通过 FastAPI 静态提供该应用。我的文件夹中有我所有的 React 构建工件static
。因此,我的 FastAPI 应用如下所示:
static/
assets/
index-lATvXaZG.js
index.html
app.py
在app.py中,我有:
app = FastAPI()
app.mount("/static", StaticFiles(directory="static"), name="react")
@app.get("")
@app.get("/")
@app.get("/index.html")
def serve_index():
return FileResponse("static/index.html")
但是,当index.html
加载时,客户端理所当然地会对 发出 GET 请求/assets/index-lATvXaZG.js
。当然,FastAPI 找不到它。
我可以在我的 React 应用程序中(或者,在我的 FastAPI 设置中)进行设置以使路径对齐吗?