Niansuh commited on
Commit
c177c86
·
verified ·
1 Parent(s): c7cc975

Update api/app.py

Browse files
Files changed (1) hide show
  1. api/app.py +42 -40
api/app.py CHANGED
@@ -1,40 +1,42 @@
1
- from fastapi import FastAPI, Request
2
- from starlette.middleware.cors import CORSMiddleware
3
- from fastapi.responses import JSONResponse
4
- from api.logger import setup_logger
5
- from api.routes import router
6
-
7
- logger = setup_logger(__name__)
8
-
9
- def create_app():
10
- app = FastAPI(
11
- title="NiansuhAI API Gateway",
12
- docs_url=None, # Disable Swagger UI
13
- redoc_url=None, # Disable ReDoc
14
- openapi_url=None, # Disable OpenAPI schema
15
- )
16
-
17
- # CORS settings
18
- app.add_middleware(
19
- CORSMiddleware,
20
- allow_origins=["*"], # Adjust as needed for security
21
- allow_credentials=True,
22
- allow_methods=["*"],
23
- allow_headers=["*"],
24
- )
25
-
26
- # Include routes
27
- app.include_router(router)
28
-
29
- # Global exception handler for better error reporting
30
- @app.exception_handler(Exception)
31
- async def global_exception_handler(request: Request, exc: Exception):
32
- logger.error(f"An error occurred: {str(exc)}")
33
- return JSONResponse(
34
- status_code=500,
35
- content={"message": "An internal server error occurred."},
36
- )
37
-
38
- return app
39
-
40
- app = create_app()
 
 
 
1
+ # api/app.py
2
+
3
+ from fastapi import FastAPI
4
+ from fastapi.middleware.cors import CORSMiddleware
5
+ from .routes import router as main_router
6
+
7
+ from .logger import setup_logger
8
+ from fastapi.responses import JSONResponse
9
+ from fastapi import Request
10
+
11
+ logger = setup_logger(__name__)
12
+
13
+ def create_app():
14
+ app = FastAPI(
15
+ title="NiansuhAI API Gateway",
16
+ docs_url=None, # Disable Swagger UI
17
+ redoc_url=None, # Disable ReDoc
18
+ openapi_url=None, # Disable OpenAPI schema
19
+ )
20
+
21
+ # CORS settings
22
+ app.add_middleware(
23
+ CORSMiddleware,
24
+ allow_origins=["*"], # Adjust as needed for security
25
+ allow_credentials=True,
26
+ allow_methods=["*"],
27
+ allow_headers=["*"],
28
+ )
29
+
30
+ # Include main routes (which now include GizAI routes)
31
+ app.include_router(main_router)
32
+
33
+ # Global exception handler for better error reporting
34
+ @app.exception_handler(Exception)
35
+ async def global_exception_handler(request: Request, exc: Exception):
36
+ logger.error(f"An error occurred: {str(exc)}", exc_info=True)
37
+ return JSONResponse(
38
+ status_code=500,
39
+ content={"message": "An internal server error occurred."},
40
+ )
41
+
42
+ return app