I am trying to send a GET request to the API, but when I add custom headers to the code, something strange happens. Somewhere, the request method changes to OPTIONS when it reaches the web server.
But when I do the same without headings, it will be a GET type. When I use the postman application (API development tool), the request works fine!
request code:
let token = this.generateClientToken(privateKey, message);
let myheaders = {
"appID": appID,
"authorizationkey": token
}
fetch('http://localhost:8080/api/app/postman', {
method: "GET",
headers: myheaders
}).then(function(response) {
console.log(response.status);
console.log(response.statusText);
console.log(response.headers);
console.log(response.url);
return response.text()
}, function(error) {
console.log(error.message);
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script>
Run codeServer log output (with headers):
worker_1 | 172.18.0.4 - 17/Mar/2017:15:47:44 +0000 "OPTIONS /index.php" 403
web_1 | 172.18.0.1 - - [17/Mar/2017:15:47:44 +0000] "OPTIONS /api/app/postman HTTP/1.1" 403 5 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:54.0) Gecko/20100101 Firefox/54.0" "-"
Server log output (without headers):
worker_1 | 172.18.0.4 - 17/Mar/2017:16:01:49 +0000 "GET /index.php" 403
web_1 | 172.18.0.1 - - [17/Mar/2017:16:01:49 +0000] "GET /api/app/postman HTTP/1.1" 403 5 "http://localhost:3000/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:54.0) Gecko/20100101 Firefox/54.0" "-"
Added NPM modules to support fetching in additional browsers:
https://github.com/github/fetch#obtaining-the-response-url
https://github.com/taylorhakes/promise-polyfill
What am I missing here? Everything looks right to me.
firefox Reactjs, NPM