diff --git a/index.js b/index.js index bc7c79f58..fb09291ab 100644 --- a/index.js +++ b/index.js @@ -18,14 +18,6 @@ sourceMapSupport.install({ }, }) -closeWithGrace(async ({ err }) => { - if (err) { - console.error(chalk.red(err)) - console.error(chalk.red(err.stack)) - process.exit(1) - } -}) - if (process.env.MOCKS === 'true') { await import('./tests/mocks/index.ts') } diff --git a/server/index.ts b/server/index.ts index 4575e78ee..45aec8c56 100644 --- a/server/index.ts +++ b/server/index.ts @@ -1,6 +1,7 @@ import crypto from 'node:crypto' import { createRequestHandler } from '@remix-run/express' import { type ServerBuild } from '@remix-run/node' +import Sentry from '@sentry/remix' import { ip as ipAddress } from 'address' import chalk from 'chalk' import closeWithGrace from 'close-with-grace' @@ -15,8 +16,9 @@ const MODE = process.env.NODE_ENV ?? 'development' const IS_PROD = MODE === 'production' const IS_DEV = MODE === 'development' const ALLOW_INDEXING = process.env.ALLOW_INDEXING !== 'false' +const SENTRY_ENABLED = IS_PROD && process.env.SENTRY_DSN -if (IS_PROD && process.env.SENTRY_DSN) { +if (SENTRY_ENABLED) { void import('./utils/monitoring.js').then(({ init }) => init()) } @@ -276,8 +278,16 @@ ${chalk.bold('Press Ctrl+C to stop')} ) }) -closeWithGrace(async () => { +closeWithGrace(async ({ err }) => { await new Promise((resolve, reject) => { server.close((e) => (e ? reject(e) : resolve('ok'))) }) + if (err) { + console.error(chalk.red(err)) + console.error(chalk.red(err.stack)) + if (SENTRY_ENABLED) { + Sentry.captureException(err) + await Sentry.flush(500) + } + } })