How to get https API response body on proxyRes
Hello all!
I have an http and an https API.
When I use http API, when user login successfully I get access token on proxyRes and I add HttpOnly Cookie. This is working.
But when I use https API I can't get response body. In my opinion because the response body is encrypted.
How can I solution this problem. Is there a solution?
This my code snippet;
function interceptLoginResponse(proxyRes, req, res) {
// Read the API's response body from
let apiResponseBody = ''
proxyRes.on('data', (chunk) => {
chunk = chunk.toString('utf-8');
apiResponseBody += chunk
})
proxyRes.on('end', async () => {
try {
// Extract the authToken from API's response:
const {access_token} = await JSON.parse(apiResponseBody);
const cookies = new Cookies(req, res, {secure: true})
await cookies.set('access_token', access_token, { secure:true, pat:"/", httpOnly: true, sameSite: 'Strict', expirationDate:"21 Oct 2022 07:28:00 GMT"})
await res.status(200).json({ success: true })
} catch (err) {
reject(err)
}
})
}