1
- from datetime import datetime
2
1
from fastapi .staticfiles import StaticFiles
2
+ import typing as T
3
3
4
4
from fastapi import FastAPI , Response
5
5
from fastapi .middleware .cors import CORSMiddleware
6
+ from fastapi .middleware import Middleware
6
7
7
8
import api
8
- from core .settings import get_settings
9
-
10
- env = get_settings ()
9
+ from core .settings import env
11
10
12
11
13
12
def init_router (app : FastAPI ):
@@ -17,28 +16,30 @@ def init_router(app: FastAPI):
17
16
name = "result image" ,
18
17
)
19
18
app .include_router (api .StableDiffusionRouter )
19
+ app .include_router (api .HomeRouter )
20
20
app .router .redirect_slashes = False
21
21
22
22
23
23
def create_app () -> FastAPI :
24
- app = FastAPI (redoc_url = None )
25
-
26
- init_cors ( app )
27
- init_middleware ( app )
24
+ app = FastAPI (
25
+ redoc_url = None ,
26
+ middleware = init_middleware (),
27
+ )
28
28
init_router (app )
29
- init_settings (app )
30
29
return app
31
30
32
31
33
- def init_cors (app : FastAPI ):
34
- app .add_middleware (
35
- CORSMiddleware ,
36
- allow_origins = env .CORS_ALLOW_ORIGINS ,
37
- )
38
-
39
-
40
- def init_middleware (app : FastAPI ):
41
- pass
32
+ def init_middleware () -> T .List [Middleware ]:
33
+ middleware = [
34
+ Middleware (
35
+ CORSMiddleware ,
36
+ allow_origins = env .CORS_ALLOW_ORIGINS ,
37
+ allow_credentials = env .CORS_CREDENTIALS ,
38
+ allow_methods = env .CORS_ALLOW_METHODS ,
39
+ allow_headers = env .CORS_ALLOW_HEADERS ,
40
+ ),
41
+ ]
42
+ return middleware
42
43
43
44
44
45
def init_settings (app : FastAPI ):
@@ -50,12 +51,6 @@ def startup_event():
50
51
def shutdown_event ():
51
52
pass
52
53
53
- @app .get ("/" )
54
- async def index ():
55
- """ELB check"""
56
- current_time = datetime .utcnow ()
57
- msg = f"Notification API (UTC: { current_time .strftime ('%Y.%m.%d %H:%M:%S' )} )"
58
- return Response (msg )
59
-
60
54
61
55
app = create_app ()
56
+ init_settings (app )
0 commit comments