Skip to content
Snippets Groups Projects
app.py 840 B
Newer Older
  • Learn to ignore specific revisions
  • """Geomag Web Services
    
    This is an Application Server Gateway Interface (ASGI) application
    and can be run using uvicorn, or any other ASGI server:
    
        uvicorn geomagio.api:app
    
    from fastapi import FastAPI
    from starlette.responses import RedirectResponse
    
    from . import secure, ws
    
    # configure logging
    DEBUG = os.getenv('DEBUG', 'false')
    LOG_LEVEL = logging.DEBUG if DEBUG == "true" else logging.INFO
    logging.basicConfig(level=LOG_LEVEL)
    
    
    app = FastAPI()
    
    app.mount("/ws", ws.app)
    
    @app.on_event("startup")
    async def on_startup():
        await database.connect()
    
    
    @app.on_event("shutdown")
    async def on_shutdown():
        await database.disconnect()
    
    
    
    @app.get("/", include_in_schema=False)
    async def redirect_to_ws():
        return RedirectResponse("/ws")