def get_fastapi_app(title: str = "", debug: bool = False, version: str = "0.0.0"): initial_app = FastAPI(title=title, debug=debug, version=version) initial_app.add_middleware( CORSMiddleware, allow_origins=ALLOWED_HOSTS or ["*"], allow_credentials=True, allow_methods=["*"], allow_headers=["*"], ) # App Startup/Shutdown Events initial_app.add_event_handler("startup", create_start_app_handler(initial_app)) initial_app.add_event_handler("shutdown", create_stop_app_handler(initial_app)) # Exception Handlers initial_app.add_exception_handler(HTTPException, http_error_handler) initial_app.add_exception_handler(RequestValidationError, http422_error_handler) # Add Routes initial_app.include_router(api_router, prefix=API_PREFIX) return initial_app
def get_application() -> FastAPI: application = FastAPI(title=PROJECT_NAME, debug=DEBUG, version=VERSION) application.add_middleware( CORSMiddleware, allow_origins=ALLOWED_HOSTS or ["*"], allow_credentials=True, allow_methods=["*"], allow_headers=["*"], ) application.mount("/static", StaticFiles(directory="static"), name="static") application.add_event_handler("startup", create_start_app_handler(application)) application.add_event_handler("shutdown", create_stop_app_handler(application)) application.add_exception_handler(HTTPException, http_error_handler) application.add_exception_handler(RequestValidationError, http422_error_handler) application.include_router(api_router, prefix=API_PREFIX) application.include_router(html_router, prefix='') return application
def get_application() -> FastAPI: settings = get_app_settings() settings.configure_logging() application = FastAPI(**settings.fastapi_kwargs) application.add_middleware( CORSMiddleware, allow_origins=settings.allowed_hosts, allow_credentials=True, allow_methods=["*"], allow_headers=["*"], ) application.add_event_handler( "startup", create_start_app_handler(application, settings), ) application.add_event_handler( "shutdown", create_stop_app_handler(application), ) application.add_exception_handler(HTTPException, http_error_handler) application.add_exception_handler(RequestValidationError, http422_error_handler) application.include_router(api_router, prefix=settings.api_prefix) return application
def get_application(): application = FastAPI(title='FastAPI') application.add_event_handler("startup", create_start_app_handler(application)) application.add_event_handler("shutdown", create_stop_app_handler(application)) application.include_router(api_router, prefix='/api') application.add_exception_handler(HTTPException, http_error_handler) return application
def get_application() -> FastAPI: application = FastAPI(title="chamcong_recognition", version="2.0") # event handler: start and stop service application.add_event_handler("startup", create_start_app_handler(application)) application.add_event_handler("shutdown", create_stop_app_handler(application)) # application.include_router(discovery_router, prefix="/chamcong/producer") return application
def get_application() -> FastAPI: application = FastAPI() application.add_event_handler("startup", create_start_app_handler(application)) application.add_event_handler("shutdown", create_stop_app_handler(application)) application.add_exception_handler(HTTPException, http_error_handler) application.add_exception_handler(RequestValidationError, http422_error_handler) application.include_router(api_router, prefix=API_PREFIX) return application
def get_application() -> FastAPI: application = FastAPI(debug=True) application.add_middleware( CORSMiddleware, allow_origins=ALLOWED_HOSTS or ["*"], allow_credentials=True, allow_methods=["*"], allow_headers=["*"], ) application.add_event_handler("startup", create_start_app_handler(application)) application.add_event_handler("shutdown", create_stop_app_handler(application)) application.include_router(api_router) return application
def get_application() -> FastAPI: application = FastAPI(title=PROJECT_NAME, debug=DEBUG, version=VERSION) application.add_middleware( CORSMiddleware, allow_origins=["*"], allow_credentials=True, allow_methods=["*"], allow_headers=["*"], ) application.add_event_handler("startup", create_start_app_handler(application)) application.add_event_handler("shutdown", create_stop_app_handler(application)) application.include_router(api_router) return application
def get_application(): fastapi_app = FastAPI(title=config.PROJECT_NAME, version=config.VERSION) fastapi_app.add_middleware( CORSMiddleware, allow_origins=["*"], allow_credentials=True, allow_methods=["*"], allow_headers=["*"], ) fastapi_app.add_event_handler("startup", events.create_start_app_handler(fastapi_app)) fastapi_app.add_event_handler("shutdown", events.create_stop_app_handler(fastapi_app)) fastapi_app.include_router(api_router, prefix="/api") return fastapi_app
def get_application() -> FastAPI: application = FastAPI() allowed: List[str] = ["*"] application.add_middleware(CORSMiddleware, allow_origins=ALLOWED_HOSTS or allowed, allow_credentials=True, allow_methods=allowed, allow_headers=allowed) application.add_event_handler("startup", create_start_app_handler(application)) application.add_event_handler("shutdown", create_stop_app_handler(application)) application.add_exception_handler(HTTPException, http_error_handler) application.add_exception_handler(RequestValidationError, http422_error_handler) application.add_exception_handler(AuthError, auth_error_handler) application.include_router(api_router, prefix=API_PREFIX) return application
def get_application() -> FastAPI: application = FastAPI(title=PROJECT_NAME, debug=DEBUG, version=VERSION) application.add_middleware( CORSMiddleware, allow_origins=ALLOWED_HOSTS or ['*'], allow_credentials=True, allow_methods=['*'], allow_headers=['*'], ) application.add_event_handler('startup', create_start_app_handler(application)) application.add_event_handler('shutdown', create_stop_app_handler(application)) application.add_exception_handler(HTTPException, http_error_handler) application.add_exception_handler(RequestValidationError, http422_error_handler) application.include_router(api_router, prefix=API_PREFIX) return application
def get_application() -> FastAPI: application = FastAPI(title=PROJECT_NAME, debug=DEBUG) application.add_middleware(GZipMiddleware) application.add_middleware( CORSMiddleware, allow_origins=ALLOWED_HOSTS or ["*"], allow_credentials=True, allow_methods=["*"], allow_headers=["*"], ) application.add_event_handler("startup", create_start_app_handler(application)) application.add_event_handler("shutdown", create_stop_app_handler(application)) application.add_exception_handler(HTTPException, http_error_handler) application.include_router(api_router, prefix=API_PREFIX) return application