-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
76 lines (59 loc) · 2.14 KB
/
main.py
File metadata and controls
76 lines (59 loc) · 2.14 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
"""
Mobile Wedding Invitation App with Admin Panel
- A simple web application for a wedding invitation.
- Features guestbook, RSVP, AI chatbot, and admin panel functionalities.
- Uses FastAPI for backend and Jinja2 for templating.
- Supports both local SQLite and PostgreSQL (Railway) databases.
- Clean modular structure with app/ backend organization.
- Developed by Soohwan Kim & Claude-4
"""
import os
import logging
from fastapi import FastAPI
from fastapi.staticfiles import StaticFiles
from starlette.middleware.sessions import SessionMiddleware
# 코어 모듈
from app.core import config, init_db, migrate_database, init_chatbot, SECRET_KEY, APP_TITLE, DATABASE_URL
# 라우터
from app.routers import home, guestbook, rsvp, admin, chatbot, stats, photos
# 로깅 설정
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
# FastAPI 앱 생성
app = FastAPI(title=APP_TITLE)
# 미들웨어
app.add_middleware(SessionMiddleware, secret_key=SECRET_KEY)
# 정적 파일
app.mount("/static", StaticFiles(directory="static"), name="static")
# 라우터 등록
app.include_router(home.router)
app.include_router(guestbook.router)
app.include_router(rsvp.router)
app.include_router(admin.router)
app.include_router(chatbot.router)
app.include_router(stats.router)
app.include_router(photos.router)
@app.on_event("startup")
async def startup_event():
"""앱 시작시 초기화"""
logger.info("애플리케이션 시작 중...")
# 환경변수 확인
if DATABASE_URL:
logger.info("✅ PostgreSQL 데이터베이스 사용 (프로덕션)")
else:
logger.info("⚠️ SQLite 데이터베이스 사용 (개발환경)")
# 데이터베이스 초기화
try:
init_db()
logger.info("✅ 데이터베이스 초기화 완료")
# 마이그레이션 실행
migrate_database()
except Exception as e:
logger.error(f"❌ 데이터베이스 초기화 실패: {e}")
raise e
# 챗봇 초기화
init_chatbot()
if __name__ == "__main__":
import uvicorn
port = int(os.getenv("PORT", 8000))
uvicorn.run("main:app", host="0.0.0.0", port=port, reload=False)