-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
69 lines (53 loc) · 1.85 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
57
58
59
60
61
62
63
64
65
66
67
68
69
import os
import sys
import uvicorn
from fastapi import FastAPI, Request, Response, WebSocket
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import JSONResponse, RedirectResponse
from fastapi.templating import Jinja2Templates
from pydantic import BaseModel
sys.path.append("./")
sys.path.append("./front")
sys.path.append("./back")
from config import *
from back.kakao import router as kakao_router # 카카오 로그인 라우터 불러오기
from back.users import router as user_router # MongoDB 라우터 불러오기
# redirect URI 자동 설정
app = FastAPI(docs_url="/documentation", redoc_url=None)
app.include_router(kakao_router, prefix="/kakao")
app.include_router(user_router, prefix="/users")
origins = [
f"http://{INSIDE_IP}:{PORT}",
f"http://{OUTSIDE_IP}:{PORT}", f"http://{OUTSIDE_IP}:{STREAMLIT_PORT}", f"http://localhost:{PORT}",
]
app.add_middleware(
CORSMiddleware,
# allow_origins=origins,
allow_origins=["*"], # 모든 출처 허용
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# WebSocket
@app.websocket("/ws")
async def websocket_endpoint(websocket: WebSocket):
await websocket.accept()
await websocket.send_json("FAST API")
# return
# 미들웨어 : 모든 Path 에서 동작
@app.middleware("http")
async def add_process_time_header(request: Request, call_next):
response = await call_next(request)
return response
@app.route('/{_:path}')
async def https_redirect(request: Request):
if request.url.scheme == "http":
return RedirectResponse(request.url.replace(scheme='https'))
# 첫 시작 페이지
@app.get("/")
def read_root():
return RedirectResponse(url=f"http://{OUTSIDE_IP}:{STREAMLIT_PORT}")
class AccessToken(BaseModel):
access_token: str
if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=PORT)