tomkuijsten / restup

Webserver for universal windows platform (UWP) apps
MIT License
114 stars 48 forks source link

Difference POSTMAN and Javascript sending header #137

Open faruk-redzic-sn opened 6 years ago

faruk-redzic-sn commented 6 years ago

Hello, When I add header using Postman everything goes fine, but when I'm using javascript(fetch) I don't get added header on server side after request is handled. What am I missing?

Jark commented 6 years ago

Hi faruk,

This doesn't sound like a problem in restup to me.

Can you provide me with a test case where restup doesn't do something that it should?

Jark

f4rukr commented 6 years ago

Hello Jark, Thank you for your response. This is my code which I've written in Vue.js using fetch. requestMethod(url) { fetch(url, { method: 'post', headers: new Headers({ 'Authorization': this.token }) }); } I don't get my added headers on server side after request is parsed from stream. Only the default once which are defined on restup. Am I missing something? Regards

Jark commented 6 years ago

Hi Faruk,

Where is the JavaScript hosted?

If the domain of where restup is running is different to the domain that you are sending in the request from (like localhost or some external site), you'll need to take cors into account.

From reading this: https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch, it seems you will need to set mode: cors if you're doing any cross site scripting.

And you'll need to (most likely) set withCredentials: true as well to ensure cookies and I think authorization headers

I would compare the request from Post man and the request you're sending yourself using the chrome dev tools and see where the difference lies.

Hope the above helps, I don't have time right now to set up a test case using restup, but will have a bit more time later this week if the above is not helpful to you.

Regards,

Jark