feat: make electron shell host CLI server

This commit is contained in:
Shantur Rathore
2025-11-20 10:41:07 +00:00
parent bc5423ce14
commit c5fd5694ee
12 changed files with 782 additions and 679 deletions

View File

@@ -89,8 +89,8 @@ function parseCliOptions(argv: string[]): CliOptions {
function parsePort(input: string): number {
const value = Number(input)
if (!Number.isInteger(value) || value < 1 || value > 65535) {
throw new InvalidArgumentError("Port must be an integer between 1 and 65535")
if (!Number.isInteger(value) || value < 0 || value > 65535) {
throw new InvalidArgumentError("Port must be an integer between 0 and 65535")
}
return value
}

View File

@@ -79,7 +79,32 @@ export function createHttpServer(deps: HttpServerDeps) {
return {
instance: app,
start: () => app.listen({ port: deps.port, host: deps.host }),
start: async () => {
const addressInfo = await app.listen({ port: deps.port, host: deps.host })
let actualPort = deps.port
if (typeof addressInfo === "string") {
try {
const parsed = new URL(addressInfo)
actualPort = Number(parsed.port) || deps.port
} catch {
actualPort = deps.port
}
} else {
const address = app.server.address()
if (typeof address === "object" && address) {
actualPort = address.port
}
}
const displayHost = deps.host === "0.0.0.0" ? "127.0.0.1" : deps.host
deps.serverMeta.httpBaseUrl = `http://${displayHost}:${actualPort}`
deps.logger.info({ port: actualPort, host: deps.host }, "HTTP server listening")
console.log(`CodeNomad Server is ready at http://${displayHost}:${actualPort}`)
return actualPort
},
stop: () => {
closeSseClients()
return app.close()