Skip to content

Media type #8

@kstrassheim

Description

@kstrassheim

Add this to main.py

dist = Path("./dist")
frontend_router = APIRouter()
@frontend_router.get('/{path:path}')
async def frontend_handler(path: str):
fp = dist / path
if path == '' or not fp.exists():
fp = dist / "index.html"

# Set correct MIME types for JavaScript modules

media_type = None
if path.endswith('.js'):
media_type = "application/javascript"
elif path.endswith('.css'):
media_type = "text/css"
elif path.endswith('.html'):
media_type = "text/html"
elif path.endswith('.json'):
media_type = "application/json"

Pass the media_type to FileResponse

return FileResponse(fp, media_type=media_type)

return FileResponse(fp)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions