TK-FB(공장관리+신고)와 M-Project(부적합관리)를 3개 독립 시스템으로 분리하기 위한 전체 코드 구조 작성. - SSO 인증 서비스 (bcrypt + pbkdf2 이중 해시 지원) - System 1: 공장관리 (TK-FB 기반, 신고 코드 제거) - System 2: 신고 (TK-FB에서 workIssue 코드 추출) - System 3: 부적합관리 (M-Project 기반) - Gateway 포털 (path-based 라우팅) - 통합 docker-compose.yml 및 배포 스크립트 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
70 lines
2.0 KiB
Python
70 lines
2.0 KiB
Python
from fastapi import FastAPI, Request
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
from fastapi.responses import JSONResponse
|
|
import uvicorn
|
|
|
|
from database.database import engine, get_db
|
|
from database.models import Base
|
|
from routers import auth, issues, daily_work, reports, projects, page_permissions, inbox, management
|
|
from services.auth_service import create_admin_user
|
|
|
|
# 데이터베이스 테이블 생성
|
|
# 메타데이터 캐시 클리어
|
|
Base.metadata.clear()
|
|
Base.metadata.create_all(bind=engine)
|
|
|
|
# FastAPI 앱 생성
|
|
app = FastAPI(
|
|
title="M-Project API",
|
|
description="작업보고서 시스템 API",
|
|
version="1.0.0"
|
|
)
|
|
|
|
# CORS 설정 (완전 개방 - CORS 문제 해결)
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=["*"],
|
|
allow_credentials=False, # * origin과 credentials는 함께 사용 불가
|
|
allow_methods=["GET", "POST", "PUT", "DELETE", "OPTIONS"],
|
|
allow_headers=["*"],
|
|
expose_headers=["*"]
|
|
)
|
|
|
|
# 라우터 등록
|
|
app.include_router(auth.router)
|
|
app.include_router(issues.router)
|
|
app.include_router(inbox.router) # 수신함 라우터 추가
|
|
app.include_router(daily_work.router)
|
|
app.include_router(reports.router)
|
|
app.include_router(projects.router)
|
|
app.include_router(page_permissions.router)
|
|
app.include_router(management.router) # 관리함 라우터 추가
|
|
|
|
# 시작 시 관리자 계정 생성
|
|
@app.on_event("startup")
|
|
async def startup_event():
|
|
db = next(get_db())
|
|
create_admin_user(db)
|
|
db.close()
|
|
|
|
# 루트 엔드포인트
|
|
@app.get("/")
|
|
async def root():
|
|
return {"message": "M-Project API", "version": "1.0.0"}
|
|
|
|
# 헬스체크
|
|
@app.get("/api/health")
|
|
async def health_check():
|
|
return {"status": "healthy"}
|
|
|
|
# 전역 예외 처리
|
|
@app.exception_handler(Exception)
|
|
async def global_exception_handler(request: Request, exc: Exception):
|
|
return JSONResponse(
|
|
status_code=500,
|
|
content={"detail": f"Internal server error: {str(exc)}"}
|
|
)
|
|
|
|
if __name__ == "__main__":
|
|
uvicorn.run(app, host="0.0.0.0", port=8000)
|