Skip to content

FastAPI app with /static mounted in main application code results in 404s #30

@zdgriffith

Description

@zdgriffith

Using code from the panel fastapi tutorial:

import panel as pn

from fastapi import FastAPI
from panel.io.fastapi import add_application

app = FastAPI()
#from fastapi.staticfiles import StaticFiles
#app.mount("/static", StaticFiles(directory="my_app/static"), name="static")

@app.get("/")
async def read_root():
    return {"Hello": "World"}


@add_application('/panel', app=app, title='My Panel App')
def create_panel_app():
    slider = pn.widgets.IntSlider(name='Slider', start=0, end=10, value=3)
    return slider.rx() * '⭐'

If I un-comment out the lines mounting a static dir the app no longer works and I get 404s from the bokeh js calls. I can get around this by changing the mount path in my app, but perhaps it would be more fool-proof if this package mounted the static files to a non-standard location? (e.g. /bokeh_static)

Thanks for your consideration.

For reference I am using:
bokeh_fastapi 0.1.3
fastapi 0.115.12
panel 1.6.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions