@@ -13,12 +13,17 @@ class StreamingResponse extends PassThrough {
13
13
outgoingMessage
14
14
METADATA_BOUNDARY = `___x_nf-metadata_boundary-${ Date . now ( ) } `
15
15
16
- constructor ( url ) {
16
+ constructor ( url , ip ) {
17
17
super ( )
18
18
// eslint-disable-next-line node/no-unsupported-features/node-builtins
19
19
const parsedUrl = new URL ( url )
20
- this . outgoingMessage =
21
- parsedUrl . protocol === 'https:' ? https . request ( url , { method : 'POST' } ) : http . request ( url , { method : 'POST' } )
20
+ const options = {
21
+ lookup : ( address , options , callback ) => {
22
+ callback ( null , ip )
23
+ } ,
24
+ method : 'POST' ,
25
+ }
26
+ this . outgoingMessage = parsedUrl . protocol === 'https:' ? https . request ( url , options ) : http . request ( url , options )
22
27
this . outgoingMessage . setHeader ( 'x-nf-metadata-boundary' , this . METADATA_BOUNDARY )
23
28
this . pipe ( this . outgoingMessage )
24
29
}
@@ -62,9 +67,9 @@ const wrapHandler =
62
67
*/
63
68
( event , context , callback ) => {
64
69
console . log ( { event } )
65
- const callbackUrl = event . queryStringParameters . callbackURL
70
+ const { callback_url : callbackUrl , target_ipv4 : callbackIP } = event . streaming
66
71
67
- if ( ! callbackUrl ) {
72
+ if ( ! callbackUrl || ! callbackIP ) {
68
73
return {
69
74
statusCode : 422 ,
70
75
body : 'Missing callback URL' ,
@@ -75,7 +80,7 @@ const wrapHandler =
75
80
let res
76
81
77
82
try {
78
- res = new StreamingResponse ( callbackUrl )
83
+ res = new StreamingResponse ( callbackUrl , callbackIP )
79
84
} catch ( error ) {
80
85
console . error ( error )
81
86
return {
0 commit comments