Toggle navigation
Toggle navigation
This project
Loading...
Sign in
万朱浩
/
Venue-Ops
Go to a project
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
alchemin
2025-11-06 15:24:24 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
f1794d4da95f4a156767eb0dba739cc793e7432f
f1794d4d
1 parent
950bf0d3
chore: add configurable HOST and PORT via .env file
支持通过.env配置服务器HOST和PORT
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
2 deletions
.env.example
app.py
config.py
.env.example
View file @
f1794d4
# ====================== BETTAFISH 相关 ======================
# BETTAFISH 主机地址,例如:0.0.0.0 或 127.0.0.1
HOST=0.0.0.0
# BETTAFISH 主机地址,默认为5000
PORT=5000
# ====================== 数据库配置 ======================
# 数据库主机,例如localhost 或 127.0.0.1
DB_HOST=your_db_host
...
...
app.py
View file @
f1794d4
...
...
@@ -47,6 +47,8 @@ LOG_DIR.mkdir(exist_ok=True)
CONFIG_MODULE_NAME
=
'config'
CONFIG_FILE_PATH
=
Path
(
__file__
)
.
resolve
()
.
parent
/
'config.py'
CONFIG_KEYS
=
[
'HOST'
,
'PORT'
,
'DB_DIALECT'
,
'DB_HOST'
,
'DB_PORT'
,
...
...
@@ -1018,8 +1020,11 @@ def handle_status_request():
})
if
__name__
==
'__main__'
:
HOST
=
'0.0.0.0'
PORT
=
5000
# 从配置文件读取 HOST 和 PORT
from
config
import
settings
HOST
=
settings
.
HOST
PORT
=
settings
.
PORT
logger
.
info
(
"等待配置确认,系统将在前端指令后启动组件..."
)
logger
.
info
(
f
"Flask服务器已启动,访问地址: http://{HOST}:{PORT}"
)
...
...
config.py
View file @
f1794d4
...
...
@@ -25,6 +25,9 @@ class Settings(BaseSettings):
全局配置;支持 .env 和环境变量自动加载。
变量名与原 config.py 大写一致,便于平滑过渡。
"""
# ================== Flask 服务器配置 ====================
HOST
:
str
=
Field
(
"0.0.0.0"
,
description
=
"Flask服务器主机地址,默认0.0.0.0(允许外部访问)"
)
PORT
:
int
=
Field
(
5000
,
description
=
"Flask服务器端口号,默认5000"
)
# ====================== 数据库配置 ======================
DB_DIALECT
:
str
=
Field
(
"mysql"
,
description
=
"数据库类型,例如 'mysql' 或 'postgresql'。用于支持多种数据库后端(如 SQLAlchemy,请与连接信息共同配置)"
)
...
...
Please
register
or
login
to post a comment