fix: 修复 SQLAlchemy 初始化和 Flask-Login user_loader 配置
- models/__init__.py 改用 extensions.py 中的 db 实例 - 添加 Flask-Login user_loader 回调函数 - 添加 nginx 反向代理配置 修复了容器启动后 API 500 错误的问题
This commit is contained in:
@@ -71,6 +71,12 @@ def _init_extensions(app):
|
|||||||
limiter.init_app(app)
|
limiter.init_app(app)
|
||||||
socketio_app.init_app(app)
|
socketio_app.init_app(app)
|
||||||
|
|
||||||
|
# 配置 Flask-Login user_loader
|
||||||
|
from app.models import User
|
||||||
|
@login_manager.user_loader
|
||||||
|
def load_user(user_id):
|
||||||
|
return User.query.get(user_id)
|
||||||
|
|
||||||
# 初始化 Redis
|
# 初始化 Redis
|
||||||
init_redis(app)
|
init_redis(app)
|
||||||
|
|
||||||
|
|||||||
@@ -3,12 +3,11 @@ PIT Router 数据模型
|
|||||||
"""
|
"""
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import Optional, List
|
from typing import Optional, List
|
||||||
from flask_sqlalchemy import SQLAlchemy
|
|
||||||
from sqlalchemy import String, DateTime, Integer, Text, JSON, ForeignKey, Boolean
|
from sqlalchemy import String, DateTime, Integer, Text, JSON, ForeignKey, Boolean
|
||||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
db = SQLAlchemy()
|
from app.extensions import db
|
||||||
|
|
||||||
|
|
||||||
def generate_uuid() -> str:
|
def generate_uuid() -> str:
|
||||||
|
|||||||
36
nginx.conf
Normal file
36
nginx.conf
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
events {
|
||||||
|
worker_connections 1024;
|
||||||
|
}
|
||||||
|
|
||||||
|
http {
|
||||||
|
upstream pit_router {
|
||||||
|
server pit-router:9000;
|
||||||
|
}
|
||||||
|
|
||||||
|
server {
|
||||||
|
listen 80;
|
||||||
|
server_name _;
|
||||||
|
|
||||||
|
location / {
|
||||||
|
proxy_pass http://pit_router;
|
||||||
|
proxy_set_header Host $host;
|
||||||
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
|
proxy_set_header X-Forwarded-Proto $scheme;
|
||||||
|
}
|
||||||
|
|
||||||
|
location /socket.io/ {
|
||||||
|
proxy_pass http://pit_router/socket.io/;
|
||||||
|
proxy_http_version 1.1;
|
||||||
|
proxy_set_header Upgrade $http_upgrade;
|
||||||
|
proxy_set_header Connection "upgrade";
|
||||||
|
proxy_set_header Host $host;
|
||||||
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
|
}
|
||||||
|
|
||||||
|
location /health {
|
||||||
|
proxy_pass http://pit_router/health;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user