@jaypie/express 1.2.8 → 1.2.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { OutgoingHttpHeaders } from "node:http";
|
|
2
2
|
import { Writable } from "node:stream";
|
|
3
3
|
import type { ResponseStream } from "./types.js";
|
|
4
|
+
export declare const JAYPIE_LAMBDA_STREAMING: unique symbol;
|
|
4
5
|
/**
|
|
5
6
|
* Mock ServerResponse that streams directly to Lambda responseStream.
|
|
6
7
|
* Uses awslambda.HttpResponseStream.from() to set status and headers.
|
package/dist/esm/index.js
CHANGED
|
@@ -624,6 +624,9 @@ class LambdaResponseBuffered extends Writable {
|
|
|
624
624
|
//
|
|
625
625
|
// Constants
|
|
626
626
|
//
|
|
627
|
+
// Symbol to identify Lambda streaming responses. Uses Symbol.for() to ensure
|
|
628
|
+
// the same symbol is used across bundles/realms. Survives prototype manipulation.
|
|
629
|
+
const JAYPIE_LAMBDA_STREAMING = Symbol.for("@jaypie/express/LambdaStreaming");
|
|
627
630
|
// Get Node's internal kOutHeaders symbol from ServerResponse prototype.
|
|
628
631
|
// This is needed for compatibility with Datadog dd-trace instrumentation,
|
|
629
632
|
// which patches HTTP methods and expects this internal state to exist.
|
|
@@ -652,6 +655,10 @@ class LambdaResponseStreaming extends Writable {
|
|
|
652
655
|
this._pendingWrites = [];
|
|
653
656
|
this._wrappedStream = null;
|
|
654
657
|
this._responseStream = responseStream;
|
|
658
|
+
// Mark as Lambda streaming response using Symbol for reliable detection.
|
|
659
|
+
// Survives prototype manipulation from Express and dd-trace.
|
|
660
|
+
this[JAYPIE_LAMBDA_STREAMING] =
|
|
661
|
+
true;
|
|
655
662
|
// Initialize Node's internal kOutHeaders for dd-trace compatibility.
|
|
656
663
|
// dd-trace patches HTTP methods and expects this internal state.
|
|
657
664
|
if (kOutHeaders) {
|
|
@@ -1024,13 +1031,6 @@ function createLambdaHandler(app, _options) {
|
|
|
1024
1031
|
await runExpressApp(app, req, res);
|
|
1025
1032
|
// Get Lambda response - await explicitly to ensure we have the result
|
|
1026
1033
|
result = await res.getResult();
|
|
1027
|
-
// Debug: Log the response before returning
|
|
1028
|
-
console.log("[createLambdaHandler] Returning response:", JSON.stringify({
|
|
1029
|
-
statusCode: result.statusCode,
|
|
1030
|
-
headers: result.headers,
|
|
1031
|
-
bodyLength: result.body?.length,
|
|
1032
|
-
isBase64Encoded: result.isBase64Encoded,
|
|
1033
|
-
}));
|
|
1034
1034
|
return result;
|
|
1035
1035
|
}
|
|
1036
1036
|
catch (error) {
|
|
@@ -1551,6 +1551,14 @@ const logger$1 = log;
|
|
|
1551
1551
|
function isLambdaMockResponse(res) {
|
|
1552
1552
|
return (res[JAYPIE_LAMBDA_MOCK] === true);
|
|
1553
1553
|
}
|
|
1554
|
+
/**
|
|
1555
|
+
* Check if response is a Lambda streaming response.
|
|
1556
|
+
* Uses Symbol marker to survive prototype chain modifications from Express and dd-trace.
|
|
1557
|
+
*/
|
|
1558
|
+
function isLambdaStreamingResponse(res) {
|
|
1559
|
+
return (res[JAYPIE_LAMBDA_STREAMING] ===
|
|
1560
|
+
true);
|
|
1561
|
+
}
|
|
1554
1562
|
/**
|
|
1555
1563
|
* Safely send a JSON response, avoiding dd-trace interception.
|
|
1556
1564
|
* For Lambda mock responses, directly manipulates internal state instead of
|
|
@@ -1583,7 +1591,16 @@ function safeSendJson(res, statusCode, data) {
|
|
|
1583
1591
|
return;
|
|
1584
1592
|
}
|
|
1585
1593
|
// Fall back to standard Express methods for real responses
|
|
1586
|
-
res.status(statusCode)
|
|
1594
|
+
res.status(statusCode);
|
|
1595
|
+
// CRITICAL: For Lambda streaming responses, flush headers before send to
|
|
1596
|
+
// initialize the stream wrapper. This ensures the status code is captured
|
|
1597
|
+
// before any writes occur (which would auto-flush with default 200).
|
|
1598
|
+
// Uses Symbol marker for reliable detection that survives prototype manipulation.
|
|
1599
|
+
if (isLambdaStreamingResponse(res) &&
|
|
1600
|
+
typeof res.flushHeaders === "function") {
|
|
1601
|
+
res.flushHeaders();
|
|
1602
|
+
}
|
|
1603
|
+
res.json(data);
|
|
1587
1604
|
}
|
|
1588
1605
|
/**
|
|
1589
1606
|
* Safely send a response body, avoiding dd-trace interception.
|
|
@@ -1611,11 +1628,20 @@ function safeSend(res, statusCode, body) {
|
|
|
1611
1628
|
return;
|
|
1612
1629
|
}
|
|
1613
1630
|
// Fall back to standard Express methods for real responses
|
|
1631
|
+
res.status(statusCode);
|
|
1632
|
+
// CRITICAL: For Lambda streaming responses, flush headers before send to
|
|
1633
|
+
// initialize the stream wrapper. This ensures the status code is captured
|
|
1634
|
+
// before any writes occur (which would auto-flush with default 200).
|
|
1635
|
+
// Uses Symbol marker for reliable detection that survives prototype manipulation.
|
|
1636
|
+
if (isLambdaStreamingResponse(res) &&
|
|
1637
|
+
typeof res.flushHeaders === "function") {
|
|
1638
|
+
res.flushHeaders();
|
|
1639
|
+
}
|
|
1614
1640
|
if (body !== undefined) {
|
|
1615
|
-
res.
|
|
1641
|
+
res.send(body);
|
|
1616
1642
|
}
|
|
1617
1643
|
else {
|
|
1618
|
-
res.
|
|
1644
|
+
res.send();
|
|
1619
1645
|
}
|
|
1620
1646
|
}
|
|
1621
1647
|
function expressHandler(handlerOrOptions, optionsOrHandler) {
|