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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/infra/Server.ts +17 -14
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "azurajs",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "Modern TypeScript-first web framework with decorator-based routing, zero dependencies, and built for performance",
5
5
  "main": "src/index.ts",
6
6
  "module": "src/index.ts",
@@ -49,7 +49,7 @@ export class AzuraClient {
49
49
  }
50
50
 
51
51
  private async init() {
52
- this.port = await getOpenPort(this.opts.server?.port || 3000);
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
- try {
99
- if (!this.server) {
100
- logger("error", "Server not initialized");
101
- return;
102
- }
98
+ if (!this.server) {
99
+ logger("error", "Server not initialized");
100
+ return;
101
+ }
103
102
 
104
- const who = cluster.isPrimary ? "master" : "worker";
105
- this.server.listen(port, () =>
106
- logger("info", `[${who}] listening on http://localhost:${port}`)
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
- } catch (error: Error | any) {
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) {