sprint-es 0.0.40 → 0.0.42

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.
@@ -312,25 +312,45 @@ class Sprint {
312
312
  return this.app.use(pathOrHandler);
313
313
  }
314
314
  listen(callback) {
315
- const port = this.app.get("port");
316
- const healthRoute = this.prefix ? `${this.prefix}/healthcheck` : "/healthcheck";
317
- this.server.listen(port, () => {
318
- const prefixInfo = this.prefix ? this.prefix : "/";
319
- const reset = "\x1B[0m";
320
- const bold = "\x1B[1m";
321
- const cyan = "\x1B[36m";
322
- const dim = "\x1B[2m";
323
- console.log("");
324
- console.log(` ${bold}${cyan}Sprint${reset} ready to handle requests`);
325
- console.log("");
326
- console.log(` ${dim}Local:${reset} http://localhost:${bold}${port}${reset}`);
327
- console.log(` ${dim}Prefix:${reset} ${bold}${prefixInfo}${reset}`);
328
- console.log(` ${dim}Healthcheck:${reset} http://localhost:${port}${healthRoute}`);
329
- console.log("");
330
- console.log(` ${dim}Tip: Need stronger route protection? Learn more at${reset}`);
331
- console.log(` ${dim}https://docs.tpeoficial.com/docs/dymo-api/private/request-verifier${reset}`);
332
- console.log("");
333
- });
315
+ const isDev2 = process.env.NODE_ENV === "development";
316
+ const basePort = this.app.get("port") || 5e3;
317
+ const triedPorts = [];
318
+ const tryListen = (port) => {
319
+ triedPorts.push(port);
320
+ this.server.listen(port, () => {
321
+ const prefixInfo = this.prefix ? this.prefix : "/";
322
+ const reset = "\x1B[0m";
323
+ const bold = "\x1B[1m";
324
+ const cyan = "\x1B[36m";
325
+ const dim = "\x1B[2m";
326
+ console.log("");
327
+ console.log(` ${bold}${cyan}Sprint${reset} ready to handle requests`);
328
+ console.log("");
329
+ console.log(` ${dim}Local:${reset} http://localhost:${bold}${port}${reset}`);
330
+ console.log(` ${dim}Prefix:${reset} ${bold}${prefixInfo}${reset}`);
331
+ console.log(` ${dim}Healthcheck:${reset} http://localhost:${port}${this.prefix}/healthcheck`);
332
+ console.log("");
333
+ console.log(` ${dim}Tip: Need stronger route protection? Learn more at${reset}`);
334
+ console.log(` ${dim}https://docs.tpeoficial.com/docs/dymo-api/private/request-verifier${reset}`);
335
+ console.log("");
336
+ });
337
+ this.server.on("error", (err) => {
338
+ if (err.code === "EADDRINUSE" && isDev2) {
339
+ const nextPort = triedPorts.length === 1 ? 3e3 : triedPorts[triedPorts.length - 1] + 1;
340
+ if (nextPort > 1e4) {
341
+ console.error(`❌ No available ports found after trying: ${triedPorts.join(", ")}`);
342
+ process.exit(1);
343
+ }
344
+ console.log(`⚠️ Port ${port} in use, trying ${nextPort}...`);
345
+ this.server.close();
346
+ tryListen(nextPort);
347
+ } else {
348
+ console.error(`❌ Server error:`, err.message);
349
+ process.exit(1);
350
+ }
351
+ });
352
+ };
353
+ tryListen(basePort);
334
354
  this.routesLoaded.then(() => {
335
355
  this.loadNotFound();
336
356
  if (callback) callback();
package/dist/esm/index.js CHANGED
@@ -309,25 +309,45 @@ class Sprint {
309
309
  return this.app.use(pathOrHandler);
310
310
  }
311
311
  listen(callback) {
312
- const port = this.app.get("port");
313
- const healthRoute = this.prefix ? `${this.prefix}/healthcheck` : "/healthcheck";
314
- this.server.listen(port, () => {
315
- const prefixInfo = this.prefix ? this.prefix : "/";
316
- const reset = "\x1B[0m";
317
- const bold = "\x1B[1m";
318
- const cyan = "\x1B[36m";
319
- const dim = "\x1B[2m";
320
- console.log("");
321
- console.log(` ${bold}${cyan}Sprint${reset} ready to handle requests`);
322
- console.log("");
323
- console.log(` ${dim}Local:${reset} http://localhost:${bold}${port}${reset}`);
324
- console.log(` ${dim}Prefix:${reset} ${bold}${prefixInfo}${reset}`);
325
- console.log(` ${dim}Healthcheck:${reset} http://localhost:${port}${healthRoute}`);
326
- console.log("");
327
- console.log(` ${dim}Tip: Need stronger route protection? Learn more at${reset}`);
328
- console.log(` ${dim}https://docs.tpeoficial.com/docs/dymo-api/private/request-verifier${reset}`);
329
- console.log("");
330
- });
312
+ const isDev2 = process.env.NODE_ENV === "development";
313
+ const basePort = this.app.get("port") || 5e3;
314
+ const triedPorts = [];
315
+ const tryListen = (port) => {
316
+ triedPorts.push(port);
317
+ this.server.listen(port, () => {
318
+ const prefixInfo = this.prefix ? this.prefix : "/";
319
+ const reset = "\x1B[0m";
320
+ const bold = "\x1B[1m";
321
+ const cyan = "\x1B[36m";
322
+ const dim = "\x1B[2m";
323
+ console.log("");
324
+ console.log(` ${bold}${cyan}Sprint${reset} ready to handle requests`);
325
+ console.log("");
326
+ console.log(` ${dim}Local:${reset} http://localhost:${bold}${port}${reset}`);
327
+ console.log(` ${dim}Prefix:${reset} ${bold}${prefixInfo}${reset}`);
328
+ console.log(` ${dim}Healthcheck:${reset} http://localhost:${port}${this.prefix}/healthcheck`);
329
+ console.log("");
330
+ console.log(` ${dim}Tip: Need stronger route protection? Learn more at${reset}`);
331
+ console.log(` ${dim}https://docs.tpeoficial.com/docs/dymo-api/private/request-verifier${reset}`);
332
+ console.log("");
333
+ });
334
+ this.server.on("error", (err) => {
335
+ if (err.code === "EADDRINUSE" && isDev2) {
336
+ const nextPort = triedPorts.length === 1 ? 3e3 : triedPorts[triedPorts.length - 1] + 1;
337
+ if (nextPort > 1e4) {
338
+ console.error(`❌ No available ports found after trying: ${triedPorts.join(", ")}`);
339
+ process.exit(1);
340
+ }
341
+ console.log(`⚠️ Port ${port} in use, trying ${nextPort}...`);
342
+ this.server.close();
343
+ tryListen(nextPort);
344
+ } else {
345
+ console.error(`❌ Server error:`, err.message);
346
+ process.exit(1);
347
+ }
348
+ });
349
+ };
350
+ tryListen(basePort);
331
351
  this.routesLoaded.then(() => {
332
352
  this.loadNotFound();
333
353
  if (callback) callback();
@@ -1 +1 @@
1
- {"version":3,"file":"sprint.d.ts","sourceRoot":"","sources":["../../src/sprint.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,OAAO,EAAE,aAAa,EAAsC,MAAM,SAAS,CAAC;AACrF,OAAO,OAAO,EAAE,EAAE,WAAW,EAAoD,MAAM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AAE,OAAO,EAAE,OAAO;IACrC,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO;IACpC,GAAG,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,EAAE,YAAY,CAAC,EAAE,OAAO;IAK/D,MAAM,CAAC,QAAQ,CAAC,EAAE,MAAM,IAAI,GAAG,IAAI;CAoDzC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sprint-es",
3
- "version": "0.0.40",
3
+ "version": "0.0.42",
4
4
  "description": "Sprint - Quickly API",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -76,6 +76,7 @@
76
76
  "dependencies": {
77
77
  "axios": "^1.13.2",
78
78
  "cors": "^2.8.5",
79
+ "dotenv": "^17.3.1",
79
80
  "express": "^5.1.0",
80
81
  "morgan": "^1.10.1",
81
82
  "node-cron": "^3.0.3",
@@ -97,7 +98,6 @@
97
98
  "@types/node": "^22.18.7",
98
99
  "@types/node-cron": "^3.0.11",
99
100
  "@types/serve-favicon": "^2.5.7",
100
- "dotenv": "^17.3.1",
101
101
  "jest": "^30.1.3",
102
102
  "rimraf": "^6.0.1",
103
103
  "ts-jest": "^29.4.4",