yaGeey commited on
Commit
19df151
·
1 Parent(s): 30df607

parse port as number

Browse files
Files changed (1) hide show
  1. src/index.ts +18 -3
src/index.ts CHANGED
@@ -8,7 +8,6 @@ import { updateAllHashes, operations, updateHash } from './hashHandlers.js'
8
  import './cronjobs.js'
9
 
10
  const app = express()
11
- const PORT = process.env.PORT || 3000
12
  export const queue: PQueue = new PQueue({ concurrency: 1 })
13
 
14
  app.use((req, res, next) => {
@@ -176,6 +175,22 @@ app.use(async (err: unknown, req: express.Request, res: express.Response, next:
176
  }
177
  })
178
 
179
- app.listen(PORT as number, '0.0.0.0', () => {
180
- console.log(`Server running on port ${PORT} at 0.0.0.0`)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
181
  })
 
8
  import './cronjobs.js'
9
 
10
  const app = express()
 
11
  export const queue: PQueue = new PQueue({ concurrency: 1 })
12
 
13
  app.use((req, res, next) => {
 
175
  }
176
  })
177
 
178
+ // TypeScript / Node.js
179
+ const portRaw = process.env.PORT ?? "3000";
180
+ const PORT = Number.parseInt(portRaw, 10);
181
+
182
+ if (!Number.isFinite(PORT) || PORT <= 0) {
183
+ throw new Error(`Invalid PORT: ${portRaw}`);
184
+ }
185
+
186
+ app.listen(PORT, "0.0.0.0", () => {
187
+ console.log(`Server listening on 0.0.0.0:${PORT}`);
188
+ });
189
+
190
+ process.on('unhandledRejection', (reason) => {
191
+ console.error('💥 Unhandled Promise Rejection:', reason)
192
+ })
193
+
194
+ process.on('uncaughtException', (err) => {
195
+ console.error('💥 Uncaught Exception:', err)
196
  })