fix: add listen for path

This commit is contained in:
熊潇 2025-05-21 17:01:08 +08:00
parent d3e17096c4
commit 1c2aa26dd0
3 changed files with 22 additions and 6 deletions

View File

@ -70,6 +70,13 @@ export type AssistantConfigData = {
proxy?: ProxyInfo[];
apiProxyList?: ProxyInfo[];
description?: string;
/**
*
*/
server?: {
path?: string;
port?: number;
};
/**
*
*/

View File

@ -7,7 +7,7 @@ import { program } from 'commander';
import { spawnSync } from 'child_process';
import chalk from 'chalk';
import { AssistantApp } from './lib.ts';
export const runServer = async (port?: number) => {
export const runServer = async (port?: number, listenPath = '127.0.0.1') => {
let _port: number | undefined;
if (port) {
_port = await getPort({ port });
@ -25,9 +25,16 @@ export const runServer = async (port?: number) => {
}
_port = isPortAvailable;
}
app.listen(_port, () => {
console.log(`Server is running on https://localhost:${_port}`);
});
const hasSocket = listenPath.includes('.sock');
if (hasSocket) {
app.listen(listenPath, () => {
console.log(`Server is running on ${listenPath}`);
});
} else {
app.listen(_port, listenPath, () => {
console.log(`Server is running on https://${listenPath}:${_port}`);
});
}
app.server.on(proxyRoute);
proxyWs();
const manager = new AssistantApp(assistantConfig, app);
@ -72,7 +79,9 @@ program
console.log('以守护进程方式运行');
} else if (options.start) {
console.log('启动服务', chalk.green(assistantConfig.configDir));
const server = await runServer(options.port);
const listenPort = options.port || assistantConfig.config?.server?.port;
const listenPath = assistantConfig.config?.server?.path || '127.0.0.1';
const server = await runServer(listenPort, listenPath);
}
});

@ -1 +1 @@
Subproject commit 0a0ffbdb235e01ee3b63745e3d4045e032d42216
Subproject commit bae8275b11d5808fd07c3172441dfc738fef525c