-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
57 lines (48 loc) · 1.52 KB
/
Copy pathmain.py
File metadata and controls
57 lines (48 loc) · 1.52 KB
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
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from contextlib import asynccontextmanager
import os
from routers import test, course, scholarship, auth
from database.db_connect import engine
from database.models import Base
from internal.scheduler import start_scheduler, scheduler
import logging
logging.basicConfig(level=logging.INFO)
# Load Server URLs for API Documentation testing (Swagger UI)
gateway_url = os.getenv("GATEWAY_URL", "http://localhost:18080")
backend_url = os.getenv("BACKEND_URL", "http://localhost:8000")
@asynccontextmanager
async def lifespan(app: FastAPI):
# Startup
start_scheduler()
yield
# Shutdown
scheduler.shutdown()
app = FastAPI(
title='Magic Pinecone Backend API',
description='A project allows NCUers to retrieval the massive campus information in this single platform.',
version='0.0.0',
contact={
'name': 'Shawn Lin',
'email': 'spig100.roc@gmail.com'
},
lifespan=lifespan,
servers=[
{"url": gateway_url, "description": "API Gateway (DigiRunner)"},
{"url": backend_url, "description": "Direct Backend (Restricted)"}
]
)
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
app.include_router(test.router)
app.include_router(course.router)
app.include_router(scholarship.router)
app.include_router(auth.router)
@app.get("/")
def root():
return {"message": "Welcome to Amazing Pinecone Backend!"}