- 사진 2장까지 업로드 지원 - 카메라 촬영 + 갤러리 선택 분리 - 이미지 압축 및 최적화 (ImageUtils) - iPhone .mpo 파일 JPEG 변환 지원 - 카테고리 변경: 치수불량 → 설계미스, 검사미스 추가 - KST 시간대 설정 - URL 해시 처리로 목록관리 페이지 이동 개선 - 로그인 OAuth2 form-data 형식 수정 - 업로드 속도 개선 및 프로그레스바 추가
65 lines
1.6 KiB
Python
65 lines
1.6 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
|
|
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 설정
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=["*"], # 프로덕션에서는 구체적인 도메인으로 변경
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
# 라우터 등록
|
|
app.include_router(auth.router)
|
|
app.include_router(issues.router)
|
|
app.include_router(daily_work.router)
|
|
app.include_router(reports.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)
|