-
Notifications
You must be signed in to change notification settings - Fork 257
Expand file tree
/
Copy pathbugsnag.js
More file actions
27 lines (24 loc) · 996 Bytes
/
bugsnag.js
File metadata and controls
27 lines (24 loc) · 996 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { PHASE_PRODUCTION_BUILD } from 'next/constants'
import Bugsnag from '@bugsnag/js'
export function start() {
// Next.js executes top-level code at build time, so use NEXT_PHASE to avoid Bugsnag.start being executed during the build phase
if (process.env.NEXT_PHASE === PHASE_PRODUCTION_BUILD) return
if (typeof window === 'undefined') {
Bugsnag.start({
apiKey: process.env.NEXT_PUBLIC_BUGSNAG_API_KEY,
appVersion: process.env.NEXT_BUILD_ID,
// @bugsnag/plugin-aws-lambda must only be imported on the server
plugins: [require('@bugsnag/plugin-aws-lambda')],
})
} else {
// If preferred two separate Bugsnag projects e.g. a javascript and a node project could be used rather than a single one
Bugsnag.start({
apiKey: process.env.NEXT_PUBLIC_BUGSNAG_API_KEY,
appVersion: process.env.NEXT_BUILD_ID,
plugins: [],
})
}
}
export function getServerlessHandler() {
return Bugsnag.getPlugin('awsLambda').createHandler()
}