@mantiq/core 0.0.2 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/http/Kernel.ts +28 -8
package/package.json
CHANGED
package/src/http/Kernel.ts
CHANGED
|
@@ -133,17 +133,37 @@ export class HttpKernel {
|
|
|
133
133
|
*/
|
|
134
134
|
async start(): Promise<void> {
|
|
135
135
|
const config = this.container.make(ConfigRepository)
|
|
136
|
-
const
|
|
136
|
+
const preferredPort = config.get<number>('app.port', 3000)
|
|
137
137
|
const hostname = config.get<string>('app.host', '0.0.0.0')
|
|
138
138
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
hostname,
|
|
142
|
-
fetch: (req, server) => this.handle(req, server),
|
|
143
|
-
websocket: this.wsKernel.getBunHandlers(),
|
|
144
|
-
})
|
|
139
|
+
let port = preferredPort
|
|
140
|
+
const maxAttempts = 20
|
|
145
141
|
|
|
146
|
-
|
|
142
|
+
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
|
143
|
+
try {
|
|
144
|
+
Bun.serve({
|
|
145
|
+
port,
|
|
146
|
+
hostname,
|
|
147
|
+
fetch: (req, server) => this.handle(req, server),
|
|
148
|
+
websocket: this.wsKernel.getBunHandlers(),
|
|
149
|
+
})
|
|
150
|
+
|
|
151
|
+
const display = hostname === '0.0.0.0' ? 'localhost' : hostname
|
|
152
|
+
if (port !== preferredPort) {
|
|
153
|
+
console.log(`Port ${preferredPort} in use, using ${port} instead`)
|
|
154
|
+
}
|
|
155
|
+
console.log(`Server running at http://${display}:${port}`)
|
|
156
|
+
return
|
|
157
|
+
} catch (err: any) {
|
|
158
|
+
if (err?.code === 'EADDRINUSE') {
|
|
159
|
+
port++
|
|
160
|
+
continue
|
|
161
|
+
}
|
|
162
|
+
throw err
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
throw new Error(`No available port found (tried ${preferredPort}–${port - 1})`)
|
|
147
167
|
}
|
|
148
168
|
|
|
149
169
|
// ── Private ───────────────────────────────────────────────────────────────
|