fastapi_spa_kit package

Module contents

fastapi_spa_kit.add_dev_spa_static_handler(app: fastapi.applications.FastAPI, directory: Union[str, os.PathLike], html_path: Union[str, os.PathLike], path: Union[str, os.PathLike] = '/static', name: str = 'static')[source]

Add to app handler that serves static files and index.html. Use only for development mode!

Parameters
  • app – FastAPI application.

  • directory – Path to static files.

  • html_path – Path to HTML file.

  • path – Route that will handle static file

  • name – Name that can be used internally by FastAPI

Example:

app = FastAPI()

# add some handlers...

# finally, add route '/static' and HTML file handler
if IS_DEV_MODE:
    add_dev_spa_static_handler(
        app,
        'path/to/static',
        'path/to/index.html'
    )