feat(server): support --host for LAN binding and export buildApp
This commit is contained in:
parent
407202f092
commit
c2e3b0298e
@ -1,5 +1,5 @@
|
||||
import { startServer } from '../../server/index.js';
|
||||
|
||||
export async function serverStart(cwd: string, options: { port?: number } = {}): Promise<void> {
|
||||
await startServer(cwd, options.port ?? 3377);
|
||||
export async function serverStart(cwd: string, options: { port: number; host: string }): Promise<void> {
|
||||
await startServer(cwd, options);
|
||||
}
|
||||
|
||||
@ -1,13 +1,25 @@
|
||||
import Fastify from 'fastify';
|
||||
import { registerRoutes } from './routes.js';
|
||||
|
||||
export async function startServer(cwd: string, port = 3377): Promise<void> {
|
||||
export function buildApp(cwd: string) {
|
||||
const app = Fastify({ logger: false });
|
||||
await registerRoutes(app, cwd);
|
||||
registerRoutes(app, cwd);
|
||||
return app;
|
||||
}
|
||||
|
||||
export async function startServer(cwd: string, options: { port?: number; host?: string } = {}): Promise<{ app: Fastify.FastifyInstance; url: string }> {
|
||||
const app = buildApp(cwd);
|
||||
const port = options.port ?? 3377;
|
||||
const host = options.host ?? '127.0.0.1';
|
||||
|
||||
try {
|
||||
await app.listen({ port, host: '127.0.0.1' });
|
||||
console.log(`AgentHub server listening on http://127.0.0.1:${port}`);
|
||||
await app.listen({ port, host });
|
||||
const address = app.server.address();
|
||||
const url = typeof address === 'string'
|
||||
? address
|
||||
: `http://${host === '0.0.0.0' ? '127.0.0.1' : host}:${address?.port ?? port}`;
|
||||
console.log(`AgentHub server listening on http://${host}:${port}`);
|
||||
return { app, url };
|
||||
} catch (err) {
|
||||
app.log.error(err);
|
||||
process.exit(1);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user