def setup_fastAPI(fh, nginx_x_accel_redirect_base=None, apache_xsendfile=None): def wsgi_application(env, start_response): trans = Bunch( response=Response(), app=Bunch(config=Bunch( nginx_x_accel_redirect_base=nginx_x_accel_redirect_base, apache_xsendfile=apache_xsendfile))) trans.response.headers['content-length'] = len(CONTENT) trans.response.set_content_type('application/octet-stream') return send_file(start_response, trans, fh) app = FastAPI() app.mount('/test/send_file', WSGIMiddleware(wsgi_application)) return app
app.add_middleware( CORSMiddleware, allow_origins=origins, allow_credentials=True, allow_methods=["*"], allow_headers=["*"], ) app.include_router(students.router) app.include_router(subjects.router) app.include_router(proctors.router) app.include_router(sessions.router) app.include_router(session.router) app.mount('/ws', socket_app) register_tortoise( app, db_url=Config.SQLALCHEMY_DATABASE_URL, modules={'models': ['app.models']}, generate_schemas=False, add_exception_handlers=True, ) @app.on_event('startup') async def starup_event(): await redis_cache.init_cache()