- Flask Blueprint 아키텍처로 전환 (dashboard, upload, backup, status) - app.py 681줄 95줄로 축소 (86% 감소) - HTML 템플릿 모듈화 (base.html + 기능별 templates) - CSS/JS 파일 분리 (common + 기능별 파일) - 대시보드 기능 추가 (통계, 주간 예보, 방문객 추이) - 파일 업로드 웹 인터페이스 구현 - 백업/복구 관리 UI 구현 - Docker 배포 환경 개선 - .gitignore 업데이트 (uploads, backups, cache 등)
70 lines
1.9 KiB
Python
70 lines
1.9 KiB
Python
# app.py
|
|
"""
|
|
POS 데이터 웹 애플리케이션
|
|
|
|
기능:
|
|
- 파일 업로드 및 처리
|
|
- 대시보드 통계 및 예측
|
|
- 데이터베이스 백업/복구
|
|
"""
|
|
|
|
import os
|
|
import sys
|
|
import logging
|
|
|
|
from flask import Flask
|
|
|
|
# 프로젝트 루트 경로 추가
|
|
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
|
|
|
|
from lib.common import setup_logging
|
|
from app.blueprints import dashboard_bp, upload_bp, backup_bp, status_bp
|
|
|
|
# 로거 설정
|
|
logger = setup_logging('pos_web_app', 'INFO')
|
|
|
|
|
|
def create_app():
|
|
"""Flask 애플리케이션 팩토리"""
|
|
|
|
# Flask 앱 초기화
|
|
app = Flask(__name__, template_folder='templates', static_folder='static')
|
|
|
|
# 설정
|
|
app.config['UPLOAD_FOLDER'] = os.path.join(os.path.dirname(__file__), '..', 'uploads')
|
|
app.config['MAX_CONTENT_LENGTH'] = 100 * 1024 * 1024 # 100MB 최대 파일 크기
|
|
app.config['JSON_AS_ASCII'] = False # 한글 JSON 지원
|
|
|
|
# 업로드 폴더 생성
|
|
os.makedirs(app.config['UPLOAD_FOLDER'], exist_ok=True)
|
|
|
|
# Blueprint 등록
|
|
app.register_blueprint(dashboard_bp)
|
|
app.register_blueprint(upload_bp)
|
|
app.register_blueprint(backup_bp)
|
|
app.register_blueprint(status_bp)
|
|
|
|
# 에러 핸들러
|
|
@app.errorhandler(413)
|
|
def handle_large_file(e):
|
|
"""파일 크기 초과"""
|
|
return {'error': '파일이 너무 큽니다 (최대 100MB)'}, 413
|
|
|
|
@app.errorhandler(500)
|
|
def handle_internal_error(e):
|
|
"""내부 서버 오류"""
|
|
logger.error(f"Internal server error: {e}")
|
|
return {'error': '서버 오류가 발생했습니다'}, 500
|
|
|
|
|
|
def run_app(host='0.0.0.0', port=8889, debug=False):
|
|
"""애플리케이션 실행"""
|
|
app = create_app()
|
|
logger.info(f"애플리케이션 시작: {host}:{port}")
|
|
app.run(host=host, port=port, debug=debug)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
run_app()
|
|
|