isomorphic-fetch icon indicating copy to clipboard operation
isomorphic-fetch copied to clipboard

Empty headers in response

Open carlosconnected opened this issue 8 years ago • 2 comments

I'm getting a successful response (200) with all the body data but the header is empty. When I try it with curl or postman I can see the headers, but fetch gets me an empty header.

fetch(endpoint, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: data}) .then(checkStatus) .then(response => response.headers ); // response.json() gets me body data

Is anybody retrieving headers successfully with isomorphic-fetch?

carlosconnected avatar Nov 28 '16 05:11 carlosconnected

Figured it out. The client wasn't the problem. Custom headers require extra configuration when doing CORS. Issue was on the server because my API was missing one line of configuration: headers: :any, expose: ['access-token', 'expiry', 'token-type', 'uid', 'client'], // Was missing this line. methods: [:get, :post, :put, :patch, :delete, :options, :head]

carlosconnected avatar Nov 28 '16 07:11 carlosconnected

Yeah I'm having the same problem too, and from what I see you're using the rack-cors gem in a rails project as I do. :) I was having the same problem using the redux-auth library that uses this library to make API calls, but turns out the problem was not any of these, was in the API as you mentioned, but I'm not missing this line, the problem is with the file:// protocol used by the electron app. Hope this comment helps anyone searching for these kind of error( it took some long days searching for the bug )

betoharres avatar Jun 19 '17 15:06 betoharres