@@ -101,15 +101,15 @@ export class AwsLambdaExtension {
101
101
*/
102
102
public startSentryTunnel ( ) : void {
103
103
const server = http . createServer ( async ( req , res ) => {
104
- if ( req . url ?. startsWith ( '/envelope' ) ) {
104
+ if ( req . method === 'POST' && req . url ?. startsWith ( '/envelope' ) ) {
105
105
try {
106
106
const buf = await buffer ( req ) ;
107
107
// Extract the actual bytes from the Buffer by slicing its underlying ArrayBuffer
108
108
// This ensures we get only the data portion without any padding or offset
109
109
const envelopeBytes = buf . buffer . slice ( buf . byteOffset , buf . byteOffset + buf . byteLength ) ;
110
110
const envelope = new TextDecoder ( ) . decode ( envelopeBytes ) ;
111
111
const piece = envelope . split ( '\n' ) [ 0 ] ;
112
- const header = JSON . parse ( piece ?? '{}' ) as { dsn ?: string } ;
112
+ const header = JSON . parse ( piece || '{}' ) as { dsn ?: string } ;
113
113
if ( ! header . dsn ) {
114
114
throw new Error ( 'DSN is not set' ) ;
115
115
}
@@ -133,11 +133,19 @@ export class AwsLambdaExtension {
133
133
res . writeHead ( 500 , { 'Content-Type' : 'application/json' } ) ;
134
134
res . end ( JSON . stringify ( { error : 'Error tunneling to Sentry' } ) ) ;
135
135
}
136
+ } else {
137
+ res . writeHead ( 404 , { 'Content-Type' : 'application/json' } ) ;
138
+ res . end ( JSON . stringify ( { error : 'Not found' } ) ) ;
136
139
}
137
140
} ) ;
138
141
139
142
server . listen ( 9000 , ( ) => {
140
143
DEBUG_BUILD && debug . log ( 'Sentry proxy listening on port 9000' ) ;
141
144
} ) ;
145
+
146
+ server . on ( 'error' , err => {
147
+ DEBUG_BUILD && debug . error ( 'Error starting Sentry proxy' , err ) ;
148
+ process . exit ( 1 ) ;
149
+ } ) ;
142
150
}
143
151
}
0 commit comments