feat(server): 支持 DANMU_API_PORT 配置主端口 (#185)
This commit is contained in:
1 parent
cb0bf051e6
commit
495665dd8d
3 files changed
+12
-4
No files matched your search
@@ -116,6 +116,7 @@ LogVar 弹幕 API 服务器
|
||||
npm start
|
||||
```
|
||||
服务器将在 `http://{ip}:9321` 运行,默认token是`87654321`。
|
||||
如需修改端口,可设置环境变量 `DANMU_API_PORT`(例如 `DANMU_API_PORT=8080 npm start`)。
|
||||
|
||||
**热更新支持**:修改 `config/.env`,应用会自动检测并重新加载配置(无需重启应用)。
|
||||
|
||||
|
||||
@@ -17,6 +17,11 @@
|
||||
# 默认值:87654321
|
||||
TOKEN=87654321
|
||||
|
||||
# API 服务监听端口
|
||||
# 默认值:9321
|
||||
# 说明:本地 Node 服务会优先读取 DANMU_API_PORT;未设置时回退到 9321
|
||||
# DANMU_API_PORT=9321
|
||||
|
||||
# 系统管理访问令牌(用于系统管理功能)
|
||||
# 如果未配置此值,则无法访问系统管理功能,需要先配置后在URL中填入此token才能打开系统管理
|
||||
# 默认值:空(不启用系统管理访问控制)
|
||||
|
||||
+6
-4
@@ -249,7 +249,7 @@ process.on('SIGTERM', cleanupWatcher);
|
||||
process.on('SIGINT', cleanupWatcher);
|
||||
|
||||
/**
|
||||
* 创建主业务服务器实例 (端口 9321)
|
||||
* 创建主业务服务器实例 (默认端口 9321,可通过 DANMU_API_PORT 配置)
|
||||
* 将 Node.js 请求转换为 Web API Request,并调用 worker.js 处理
|
||||
*/
|
||||
function createServer() {
|
||||
@@ -455,10 +455,12 @@ async function startServer() {
|
||||
// 设置 .env 文件监听
|
||||
await setupEnvWatcher();
|
||||
|
||||
// 启动主业务服务器 (9321)
|
||||
// 启动主业务服务器(默认 9321,可通过 DANMU_API_PORT 覆盖)
|
||||
const configuredMainPort = Number.parseInt(process.env.DANMU_API_PORT ?? '', 10);
|
||||
const mainPort = Number.isNaN(configuredMainPort) ? 9321 : configuredMainPort;
|
||||
mainServer = createServer();
|
||||
mainServer.listen(9321, '0.0.0.0', () => {
|
||||
console.log('Server running on http://0.0.0.0:9321');
|
||||
mainServer.listen(mainPort, '0.0.0.0', () => {
|
||||
console.log(`Server running on http://0.0.0.0:${mainPort}`);
|
||||
});
|
||||
|
||||
// 启动5321端口的代理服务
|
||||
|
||||
Reference in new issue
Block a user