@@ -15,20 +15,19 @@ import morgan from 'morgan'
15
15
installGlobals ( )
16
16
17
17
const MODE = process . env . NODE_ENV ?? 'development'
18
+ const IS_PROD = MODE === 'production'
18
19
19
- const createRequestHandler =
20
- MODE === 'production'
21
- ? Sentry . wrapExpressCreateRequestHandler ( _createRequestHandler )
22
- : _createRequestHandler
20
+ const createRequestHandler = IS_PROD
21
+ ? Sentry . wrapExpressCreateRequestHandler ( _createRequestHandler )
22
+ : _createRequestHandler
23
23
24
- const viteDevServer =
25
- MODE === 'production'
26
- ? undefined
27
- : await import ( 'vite' ) . then ( vite =>
28
- vite . createServer ( {
29
- server : { middlewareMode : true } ,
30
- } ) ,
31
- )
24
+ const viteDevServer = IS_PROD
25
+ ? undefined
26
+ : await import ( 'vite' ) . then ( vite =>
27
+ vite . createServer ( {
28
+ server : { middlewareMode : true } ,
29
+ } ) ,
30
+ )
32
31
33
32
const app = express ( )
34
33
@@ -84,7 +83,7 @@ if (viteDevServer) {
84
83
app . use ( express . static ( 'build/client' , { maxAge : '1h' } ) )
85
84
}
86
85
87
- app . get ( [ '/img/*' , '/favicons/*' ] , ( req , res ) => {
86
+ app . get ( [ '/img/*' , '/favicons/*' ] , ( _req , res ) => {
88
87
// if we made it past the express.static for these, then we're missing something.
89
88
// So we'll just send a 404 and won't bother calling other middleware.
90
89
return res . status ( 404 ) . send ( 'Not found' )
@@ -108,6 +107,7 @@ app.use((_, res, next) => {
108
107
109
108
app . use (
110
109
helmet ( {
110
+ xPoweredBy : false ,
111
111
referrerPolicy : { policy : 'same-origin' } ,
112
112
crossOriginEmbedderPolicy : false ,
113
113
contentSecurityPolicy : {
@@ -142,7 +142,7 @@ app.use(
142
142
// rate limiting because playwright tests are very fast and we don't want to
143
143
// have to wait for the rate limit to reset between tests.
144
144
const maxMultiple =
145
- MODE !== 'production' || process . env . PLAYWRIGHT_TEST_BASE_URL ? 10_000 : 1
145
+ ! IS_PROD || process . env . PLAYWRIGHT_TEST_BASE_URL ? 10_000 : 1
146
146
const rateLimitDefault = {
147
147
windowMs : 60 * 1000 ,
148
148
max : 1000 * maxMultiple ,
@@ -212,8 +212,7 @@ app.all(
212
212
serverBuild : getBuild ( ) ,
213
213
} ) ,
214
214
mode : MODE ,
215
- // @sentry /remix needs to be updated to handle the function signature
216
- build : MODE === 'production' ? await getBuild ( ) : getBuild ,
215
+ build : getBuild ,
217
216
} ) ,
218
217
)
219
218
@@ -224,29 +223,25 @@ const portToUse = await getPort({
224
223
225
224
const server = app . listen ( portToUse , ( ) => {
226
225
const addy = server . address ( )
227
- const portUsed =
228
- desiredPort === portToUse
229
- ? desiredPort
230
- : addy && typeof addy === 'object'
231
- ? addy . port
232
- : 0
226
+ const portActuallyUsed =
227
+ addy === null || typeof addy === 'string' ? 0 : addy . port
233
228
234
- if ( portUsed !== desiredPort ) {
229
+ if ( portActuallyUsed !== desiredPort ) {
235
230
console . warn (
236
231
chalk . yellow (
237
- `⚠️ Port ${ desiredPort } is not available, using ${ portUsed } instead.` ,
232
+ `⚠️ Port ${ desiredPort } is not available, using ${ portActuallyUsed } instead.` ,
238
233
) ,
239
234
)
240
235
}
241
236
console . log ( `🚀 We have liftoff!` )
242
- const localUrl = `http://localhost:${ portUsed } `
237
+ const localUrl = `http://localhost:${ portActuallyUsed } `
243
238
let lanUrl : string | null = null
244
239
const localIp = ipAddress ( ) ?? 'Unknown'
245
240
// Check if the address is a private ip
246
241
// https://en.wikipedia.org/wiki/Private_network#Private_IPv4_address_spaces
247
242
// https://github.com/facebook/create-react-app/blob/d960b9e38c062584ff6cfb1a70e1512509a966e7/packages/react-dev-utils/WebpackDevServerUtils.js#LL48C9-L54C10
248
243
if ( / ^ 1 0 [ . ] | ^ 1 7 2 [ . ] ( 1 [ 6 - 9 ] | 2 [ 0 - 9 ] | 3 [ 0 - 1 ] ) [ . ] | ^ 1 9 2 [ . ] 1 6 8 [ . ] / . test ( localIp ) ) {
249
- lanUrl = `http://${ localIp } :${ portUsed } `
244
+ lanUrl = `http://${ localIp } :${ portActuallyUsed } `
250
245
}
251
246
252
247
console . log (
0 commit comments