azurajs 1.0.3 → 1.0.4
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/infra/Server.ts +17 -14
package/package.json
CHANGED
package/src/infra/Server.ts
CHANGED
|
@@ -49,7 +49,7 @@ export class AzuraClient {
|
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
private async init() {
|
|
52
|
-
this.port =
|
|
52
|
+
this.port = this.opts.server?.port || 3000;
|
|
53
53
|
|
|
54
54
|
if (this.opts.server?.cluster && cluster.isPrimary) {
|
|
55
55
|
for (let i = 0; i < os.cpus().length; i++) cluster.fork();
|
|
@@ -95,22 +95,25 @@ export class AzuraClient {
|
|
|
95
95
|
public async listen(port = this.port) {
|
|
96
96
|
await this.initPromise;
|
|
97
97
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}
|
|
98
|
+
if (!this.server) {
|
|
99
|
+
logger("error", "Server not initialized");
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
103
102
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
logger("
|
|
107
|
-
|
|
103
|
+
this.server.on("error", (error: NodeJS.ErrnoException) => {
|
|
104
|
+
if (error.code === "EADDRINUSE") {
|
|
105
|
+
logger("error", `❌ Port ${port} is already in use. Please choose a different port.`);
|
|
106
|
+
} else {
|
|
107
|
+
logger("error", "Server failed to start: " + (error?.message || String(error)));
|
|
108
|
+
}
|
|
109
|
+
process.exit(1);
|
|
110
|
+
});
|
|
108
111
|
|
|
112
|
+
const who = cluster.isPrimary ? "master" : "worker";
|
|
113
|
+
this.server.listen(port, () => {
|
|
114
|
+
logger("info", `[${who}] listening on http://localhost:${port}`);
|
|
109
115
|
if (this.opts.server?.ipHost) getIP(port);
|
|
110
|
-
}
|
|
111
|
-
logger("error", "Server failed to start: " + error?.message || String(error));
|
|
112
|
-
process.exit(1);
|
|
113
|
-
}
|
|
116
|
+
});
|
|
114
117
|
}
|
|
115
118
|
|
|
116
119
|
private async handle(rawReq: RequestServer, rawRes: ResponseServer) {
|