Fastapi enabling Cors gives - error error serving tap http server: http: Server closed

155 Views Asked by At

Adding CORS to Python FastAPI Framework is giving this error

error   error serving tap http server: http: Server closed

Configuration -

def get_app() -> FastAPI:
    """
    Returns the FastAPI ASGI object that will be later consumed by an uvicorn worker. This is where you register
    dependencies, route prefixes, swagger tags, and associate routers to the application.
    """
    app_config = get_config()  # get config and initialise logging

    app = FastAPI(title=APPLICATION_NAME, version="0.1.0")
    log.info(f"Starting {APPLICATION_NAME} version={app_config.app_version}!")

    app.include_router(home.router, tags=["home"])
    app.include_router(health.router, tags=["health"])
    app.include_router(content_relevancy_interface.router, tags=["content-relevancy-interface"])
    app.include_router(copperfield.router, tags=["copperfield"])
    origins = [
        "https://abcc,com",
        "http://abcc.net",
        "http://localhost",
        "http://localhost:8080",
    ]

    app.add_middleware(
        CORSMiddleware,
        allow_origins=origins,
        allow_credentials=True,
        allow_methods=["*"],
        allow_headers=["*"],
    )

    app.middleware('http')(catch_exceptions_middleware)  # register global exception handler
    slash_patcher(app)
    return app

This is how it is run in a shell script

export APP_RUN="gunicorn -c /etc/gunicorn/config.py seo_automation_common_apis.fastapi_app:get_app"
.
.
Some other setup 
# Start app
$APP_RUN

It seems the error is coming from istio -

https://github.com/istio/istio/issues/44445

https://github.com/istio/istio/issues/44244

Is istio used internally in FastApi ?

Let me know if any other detail is needed/missing.

Any help is appreciated

0

There are 0 best solutions below