The below code is limited to POST, but can be easily extended to any HTTP Method
consthttps=require('https');constdestinationHostname='someurl.io'constdestinationPath='/somepath/dev/v1/hola'exports.handler=async(event)=>{event.headers=event.headers||{}console.log("event",event)letpostData=event.bodyletbodyletstatusCodeletheadersawaitnewPromise((resolve,reject)=>{letoptions={hostname:destinationHostname,port:443,path:destinationPath,method:'POST',headers:event.headers,rejectUnauthorized:false}// add additional headers if required, in my case I am setting/resetting Auth headeroptions.headers['Authorization']='Basic XXXX'// most do:options.header["X-Forwarded-Host"]=options.header.Hostdeleteoptions.header.Host// also delete the host before forwarding the requestvarreq=https.request(options,(res)=>{statusCode=res.statusCodeheaders=res.headersconsole.log('statusCode:',res.statusCode);console.log('headers:',res.headers);letchunks=[];res.on("data",function(chunk){chunks.push(chunk);});res.on("end",function(){body=Buffer.concat(chunks).toString();console.log("RES BODY: ",body)// body.toString());resolve();});})req.on('error',(e)=>{console.error(e);});req.write(postData)req.end()})return{statusCode:statusCode||200,headers:headers||{'content-type':'application/json'},body:body};};
Top comments (0)
Subscribe
For further actions, you may consider blocking this person and/or reporting abuse
Top comments (0)