I'm using react-fetching-library
to send requests to the server and I want to read response headers from my ReactJS application.
What I do is trying to read them from Headers object (headers.entries()
) after fetching but there are only two headers I can access: content-length
and content-type
.
Preflight OPTIONS
request has following headers:
Access-Control-Allow-Headers: authorization,content-type
Access-Control-Allow-Methods: GET,HEAD,PUT,PATCH,POST,DELETE
Access-Control-Allow-Origin: *
Actual response has only Access-Control-Allow-Origin: *
header
I want to read X-custom-header headers from my js code. How can I do it?
Okay, I've finally managed to solve this problem
All you need to do is to add this response header:
Access-Control-Expose-Headers: *,Authorization,X-custom-header
From now you can access custom headers from your JS