-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.py
56 lines (47 loc) · 1.09 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import os
from fastapi import FastAPI
from dotenv import load_dotenv
from fastapi.middleware.cors import CORSMiddleware
from src.configurations.databases.postgresql import Session
from src.routes import (
ml_routes,
user_routes,
main_routes
)
load_dotenv()
# Database Connection
DATABASE: Session = Session()
REST = FastAPI(
title = "NLP service",
version = os.getenv("VERSION")
)
# CORS Middleware
REST.add_middleware(
CORSMiddleware,
allow_origins = ["*"],
allow_methods = ["*"],
allow_headers = ["*"],
allow_credentials = True,
)
# Include predict route group
REST.include_router(
router = ml_routes.route,
prefix = f'/{os.getenv("VERSION")}/vertx',
tags = ["Predict"],
)
# Include user route group
REST.include_router(
router = user_routes.route,
prefix = f'/{os.getenv("VERSION")}/auth',
tags = ["User"],
)
# Include main route group
REST.include_router(
router = main_routes.route,
prefix = f'',
tags = ["Main"],
)
@REST.on_event("shutdown")
async def shutdown_event():
# Database Connection Close
DATABASE.close()