@@ -200,30 +200,30 @@ export function extractRequestData(
200
200
const requestData : { [ key : string ] : any } = { } ;
201
201
202
202
// headers:
203
- // node, express: req.headers
203
+ // node, express, nextjs : req.headers
204
204
// koa: req.header
205
205
const headers = ( req . headers || req . header || { } ) as {
206
206
host ?: string ;
207
207
cookie ?: string ;
208
208
} ;
209
209
// method:
210
- // node, express, koa: req.method
210
+ // node, express, koa, nextjs : req.method
211
211
const method = req . method ;
212
212
// host:
213
213
// express: req.hostname in > 4 and req.host in < 4
214
214
// koa: req.host
215
- // node: req.headers.host
215
+ // node, nextjs : req.headers.host
216
216
const host = req . hostname || req . host || headers . host || '<no host>' ;
217
217
// protocol:
218
- // node: <n/a>
218
+ // node, nextjs : <n/a>
219
219
// express, koa: req.protocol
220
220
const protocol =
221
221
req . protocol === 'https' || req . secure || ( ( req . socket || { } ) as { encrypted ?: boolean } ) . encrypted
222
222
? 'https'
223
223
: 'http' ;
224
224
// url (including path and query string):
225
225
// node, express: req.originalUrl
226
- // koa: req.url
226
+ // koa, nextjs : req.url
227
227
const originalUrl = ( req . originalUrl || req . url || '' ) as string ;
228
228
// absolute url
229
229
const absoluteUrl = `${ protocol } ://${ host } ${ originalUrl } ` ;
@@ -242,26 +242,27 @@ export function extractRequestData(
242
242
case 'cookies' :
243
243
// cookies:
244
244
// node, express, koa: req.headers.cookie
245
- // vercel, sails.js, express (w/ cookie middleware): req.cookies
245
+ // vercel, sails.js, express (w/ cookie middleware), nextjs : req.cookies
246
246
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
247
247
requestData . cookies = req . cookies || cookie . parse ( headers . cookie || '' ) ;
248
248
break ;
249
249
case 'query_string' :
250
250
// query string:
251
251
// node: req.url (raw)
252
- // express, koa: req.query
252
+ // express, koa, nextjs : req.query
253
253
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
254
- requestData . query_string = url . parse ( originalUrl || '' , false ) . query ;
254
+ requestData . query_string = req . query || url . parse ( originalUrl || '' , false ) . query ;
255
255
break ;
256
256
case 'data' :
257
257
if ( method === 'GET' || method === 'HEAD' ) {
258
258
break ;
259
259
}
260
- // body data: express, koa: req.body
261
-
262
- // when using node by itself, you have to read the incoming stream(see
263
- // https://nodejs.dev/learn/get-http-request-body-data-using-nodejs); if a user is doing that, we can't know
264
- // where they're going to store the final result, so they'll have to capture this data themselves
260
+ // body data:
261
+ // express, koa, nextjs: req.body
262
+ //
263
+ // when using node by itself, you have to read the incoming stream(see
264
+ // https://nodejs.dev/learn/get-http-request-body-data-using-nodejs); if a user is doing that, we can't know
265
+ // where they're going to store the final result, so they'll have to capture this data themselves
265
266
if ( req . body !== undefined ) {
266
267
requestData . data = isString ( req . body ) ? req . body : JSON . stringify ( normalize ( req . body ) ) ;
267
268
}
@@ -345,7 +346,7 @@ export function parseRequest(event: Event, req: ExpressRequest, options?: ParseR
345
346
}
346
347
347
348
// client ip:
348
- // node: req.connection.remoteAddress
349
+ // node, nextjs : req.connection.remoteAddress
349
350
// express, koa: req.ip
350
351
if ( options . ip ) {
351
352
const ip = req . ip || ( req . connection && req . connection . remoteAddress ) ;
@@ -358,6 +359,8 @@ export function parseRequest(event: Event, req: ExpressRequest, options?: ParseR
358
359
}
359
360
360
361
if ( options . transaction && ! event . transaction ) {
362
+ // TODO do we even need this anymore?
363
+ // TODO make this work for nextjs
361
364
event . transaction = extractTransaction ( req , options . transaction ) ;
362
365
}
363
366
0 commit comments