Skip to content

Commit 7ca8696

Browse files
committed
feat: modify init server
1 parent 3af7a2f commit 7ca8696

1 file changed

Lines changed: 25 additions & 5 deletions

File tree

‎src/backend/server.py‎

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,41 @@
11
import uvicorn
22

33
from fastapi import FastAPI
4+
from fastapi.middleware.cors import CORSMiddleware
5+
from backend.lib.config import set_config
46
from conf.server_conf import *
7+
from backend.router import wine_info, base
58

69

7-
app = FastAPI()
10+
def _add_middlewares(app):
11+
app.add_middleware(
12+
CORSMiddleware,
13+
allow_origins=['*'],
14+
allow_credentials=True,
15+
allow_methods=['*'],
16+
allow_headers=['*'],
17+
)
18+
return app
819

920

10-
@app.get("/")
11-
def index():
12-
return "dd"
21+
def _add_routers(app):
22+
app.include_router(router=wine_info, tags=['wine-info > wine-info'], prefix='/wine-info')
23+
app.include_router(base)
24+
return app
25+
26+
27+
def fast_api_app():
28+
app = FastAPI()
29+
app = _add_middlewares(app)
30+
app = _add_routers(app)
31+
return app
1332

1433

1534
def main():
1635
# uvicorn_options = CONFIG.get('UVICORN_OPTIONS', {})
1736
print(UVICORN_OPTIONS)
18-
uvicorn.run('server:app', host=HOST, port=PORT, **UVICORN_OPTIONS)
37+
set_config()
38+
uvicorn.run('server:fast_api_app', host=HOST, port=PORT, **UVICORN_OPTIONS)
1939

2040

2141
if __name__ == "__main__":

0 commit comments

Comments
 (0)