melina 1.1.4 → 1.1.5
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/web.ts +13 -13
package/package.json
CHANGED
package/src/web.ts
CHANGED
|
@@ -850,7 +850,10 @@ export async function serve(handler: Handler, options?: { port?: number; unix?:
|
|
|
850
850
|
server = Bun.serve(args);
|
|
851
851
|
} catch (err) {
|
|
852
852
|
if (!unix && (err.code === 'EADDRINUSE' || err.code === 'EACCES')) {
|
|
853
|
-
|
|
853
|
+
const requestedPort = (args as any).port || 3000;
|
|
854
|
+
const newPort = findAvailablePort(requestedPort + 1);
|
|
855
|
+
console.warn(`⚠️ Port ${requestedPort} unavailable, using port ${newPort} instead`);
|
|
856
|
+
(args as any).port = newPort;
|
|
854
857
|
server = Bun.serve(args);
|
|
855
858
|
} else {
|
|
856
859
|
throw err;
|
|
@@ -883,30 +886,27 @@ export async function serve(handler: Handler, options?: { port?: number; unix?:
|
|
|
883
886
|
export function findAvailablePort(startPort: number = 3001): number {
|
|
884
887
|
for (let port = startPort; port < startPort + 100; port++) {
|
|
885
888
|
try {
|
|
886
|
-
|
|
889
|
+
// Use Bun.serve to test — this is what we actually use, so it's the right probe.
|
|
890
|
+
// Bun.listen uses raw TCP which triggers EACCES on many Windows ports.
|
|
891
|
+
const testServer = Bun.serve({
|
|
887
892
|
port,
|
|
888
|
-
|
|
889
|
-
socket: {
|
|
890
|
-
close() {
|
|
891
|
-
// Close callback
|
|
892
|
-
},
|
|
893
|
-
data() {
|
|
894
|
-
// Data callback
|
|
895
|
-
},
|
|
896
|
-
},
|
|
893
|
+
fetch() { return new Response(''); },
|
|
897
894
|
});
|
|
898
|
-
|
|
895
|
+
testServer.stop(true);
|
|
899
896
|
return port;
|
|
900
897
|
} catch (e: any) {
|
|
901
898
|
if (
|
|
902
899
|
e.code !== 'EADDRINUSE' &&
|
|
903
900
|
e.code !== 'EACCES' &&
|
|
901
|
+
e.errno !== 10013 &&
|
|
904
902
|
!e.message?.includes('EADDRINUSE') &&
|
|
903
|
+
!e.message?.includes('EACCES') &&
|
|
904
|
+
!e.message?.includes('Failed to listen') &&
|
|
905
905
|
!e.message?.includes('Address already in use')
|
|
906
906
|
) {
|
|
907
907
|
throw e;
|
|
908
908
|
}
|
|
909
|
-
//
|
|
909
|
+
// Port not available, try next
|
|
910
910
|
}
|
|
911
911
|
}
|
|
912
912
|
throw new Error(`No available port found in range ${startPort}-${startPort + 99}`);
|