Skip to content

Commit 8307ff2

Browse files
committed
cursor & seer review
1 parent d98074a commit 8307ff2

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

packages/aws-serverless/src/lambda-extension/aws-lambda-extension.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,15 @@ export class AwsLambdaExtension {
101101
*/
102102
public startSentryTunnel(): void {
103103
const server = http.createServer(async (req, res) => {
104-
if (req.url?.startsWith('/envelope')) {
104+
if (req.method === 'POST' && req.url?.startsWith('/envelope')) {
105105
try {
106106
const buf = await buffer(req);
107107
// Extract the actual bytes from the Buffer by slicing its underlying ArrayBuffer
108108
// This ensures we get only the data portion without any padding or offset
109109
const envelopeBytes = buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength);
110110
const envelope = new TextDecoder().decode(envelopeBytes);
111111
const piece = envelope.split('\n')[0];
112-
const header = JSON.parse(piece ?? '{}') as { dsn?: string };
112+
const header = JSON.parse(piece || '{}') as { dsn?: string };
113113
if (!header.dsn) {
114114
throw new Error('DSN is not set');
115115
}
@@ -133,11 +133,19 @@ export class AwsLambdaExtension {
133133
res.writeHead(500, { 'Content-Type': 'application/json' });
134134
res.end(JSON.stringify({ error: 'Error tunneling to Sentry' }));
135135
}
136+
} else {
137+
res.writeHead(404, { 'Content-Type': 'application/json' });
138+
res.end(JSON.stringify({ error: 'Not found' }));
136139
}
137140
});
138141

139142
server.listen(9000, () => {
140143
DEBUG_BUILD && debug.log('Sentry proxy listening on port 9000');
141144
});
145+
146+
server.on('error', err => {
147+
DEBUG_BUILD && debug.error('Error starting Sentry proxy', err);
148+
process.exit(1);
149+
});
142150
}
143151
}

0 commit comments

Comments
 (0)