File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ export interface ProxyConfig {
99 aggregationIntervalMs : number ;
1010 maxRequestsPerMinute : number ;
1111 tokenMultiplier : number ;
12+ autoPort : boolean ;
1213}
1314
1415// 解析 TOKEN_MULTIPLIER,兼容常见字符串形式:
@@ -55,7 +56,12 @@ export function loadConfig(): ProxyConfig {
5556 throw new Error ( "UPSTREAM_BASE_URL must be provided" ) ;
5657 }
5758
58- const port = Number ( Deno . env . get ( "PORT" ) ?? "3456" ) ;
59+ // 检查是否启用自动端口配置
60+ const autoPort = Deno . env . get ( "AUTO_PORT" ) === "true" ;
61+
62+ // 如果启用自动端口,则使用 0 让系统自动分配端口
63+ // 否则使用环境变量指定的端口或默认端口 3456
64+ const port = autoPort ? 0 : Number ( Deno . env . get ( "PORT" ) ?? "3456" ) ;
5965 const host = Deno . env . get ( "HOST" ) ?? "0.0.0.0" ;
6066 const upstreamApiKey = Deno . env . get ( "UPSTREAM_API_KEY" ) ;
6167 const upstreamModelOverride = Deno . env . get ( "UPSTREAM_MODEL" ) ;
@@ -77,5 +83,6 @@ export function loadConfig(): ProxyConfig {
7783 aggregationIntervalMs,
7884 maxRequestsPerMinute,
7985 tokenMultiplier,
86+ autoPort,
8087 } ;
8188}
Original file line number Diff line number Diff line change @@ -277,4 +277,4 @@ serve((req) => {
277277 }
278278
279279 return new Response ( "Not Found" , { status : 404 } ) ;
280- } , { hostname : config . host , port : config . port } ) ;
280+ } , config . autoPort ? undefined : { hostname : config . host , port : config . port } ) ;
You can’t perform that action at this time.
0 commit comments