-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.py
More file actions
37 lines (32 loc) · 1.17 KB
/
run.py
File metadata and controls
37 lines (32 loc) · 1.17 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
from app import create_app, db
from app.models import User, Owner, PropertyStaff, Announcement, CommunityPost
from config import config
import os
from datetime import datetime, timedelta
app = create_app('development') # 开发环境使用development配置
# 在应用上下文中创建数据库表(首次创建时会触发 app.seed.seed_demo)
with app.app_context():
db.create_all()
@app.after_request
def after_request(response):
"""添加统一的响应头"""
response.headers.add('Access-Control-Allow-Origin', '*')
response.headers.add('Access-Control-Allow-Headers', 'Content-Type,Authorization')
response.headers.add('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS')
return response
@app.route('/')
def index():
return {
'code': 200,
'message': '幸福小区APP后端服务运行正常',
'data': {
'version': '1.0.0',
'api_base': '/api/v1'
}
}
if __name__ == '__main__':
# 从配置中获取主机和端口,确保与config.py同步
cfg = config['development']
host = os.getenv('HOST', '0.0.0.0')
port = cfg.PORT
app.run(host=host, port=port, debug=True)