@@ -16,6 +16,7 @@ installGlobals()
16
16
17
17
const MODE = process . env . NODE_ENV ?? 'development'
18
18
const IS_PROD = MODE === 'production'
19
+ const IS_DEV = MODE === "development"
19
20
20
21
const createRequestHandler = IS_PROD
21
22
? Sentry . wrapExpressCreateRequestHandler ( _createRequestHandler )
@@ -220,28 +221,29 @@ const desiredPort = Number(process.env.PORT || 3000)
220
221
const portToUse = await getPort ( {
221
222
port : portNumbers ( desiredPort , desiredPort + 100 ) ,
222
223
} )
224
+ const portAvailable = desiredPort === portToUse
225
+ if ( ! portAvailable && ! IS_DEV ) {
226
+ console . log ( `⚠️ Port ${ desiredPort } is not available.` )
227
+ process . exit ( 1 )
228
+ }
223
229
224
230
const server = app . listen ( portToUse , ( ) => {
225
- const addy = server . address ( )
226
- const portActuallyUsed =
227
- addy === null || typeof addy === 'string' ? 0 : addy . port
228
-
229
- if ( portActuallyUsed !== desiredPort ) {
231
+ if ( ! portAvailable ) {
230
232
console . warn (
231
233
chalk . yellow (
232
- `⚠️ Port ${ desiredPort } is not available, using ${ portActuallyUsed } instead.` ,
234
+ `⚠️ Port ${ desiredPort } is not available, using ${ portToUse } instead.` ,
233
235
) ,
234
236
)
235
237
}
236
238
console . log ( `🚀 We have liftoff!` )
237
- const localUrl = `http://localhost:${ portActuallyUsed } `
239
+ const localUrl = `http://localhost:${ portToUse } `
238
240
let lanUrl : string | null = null
239
241
const localIp = ipAddress ( ) ?? 'Unknown'
240
242
// Check if the address is a private ip
241
243
// https://en.wikipedia.org/wiki/Private_network#Private_IPv4_address_spaces
242
244
// https://github.com/facebook/create-react-app/blob/d960b9e38c062584ff6cfb1a70e1512509a966e7/packages/react-dev-utils/WebpackDevServerUtils.js#LL48C9-L54C10
243
245
if ( / ^ 1 0 [ . ] | ^ 1 7 2 [ . ] ( 1 [ 6 - 9 ] | 2 [ 0 - 9 ] | 3 [ 0 - 1 ] ) [ . ] | ^ 1 9 2 [ . ] 1 6 8 [ . ] / . test ( localIp ) ) {
244
- lanUrl = `http://${ localIp } :${ portActuallyUsed } `
246
+ lanUrl = `http://${ localIp } :${ portToUse } `
245
247
}
246
248
247
249
console . log (
0 commit comments