I'm trying to make a GET/POST request with fetch in service worker file, but it sends only OPTIONS request and not sending my original request. below is my code:
fetch('http://cross-origin-server/controller/function',{
headers: {
"x-app-header": 'app'
},
"mod":"no-cors"
}).then(function(response) {
console.log(response);
});
Here are the request and response headers :
Request Headers
Accept:*/*
Accept-Encoding:gzip, deflate
Accept-Language:en-GB,en-US;q=0.9,en;q=0.8
Access-Control-Request-Headers:x-custom-header
Access-Control-Request-Method:GET
Cache-Control:no-cache
Connection:keep-alive
Host:192.168.1.215
Origin:http://localhost:3000
Response Header
Access-Control-Allow-Headers:Content-Type, Content-Length, Accept-Encoding, Authorization,Cache-Control, x-custom-header, x-requested-with
Access-Control-Allow-Methods:GET, OPTIONS
Access-Control-Allow-Origin:*
Cache-Control:no-store, no-cache, must-revalidate
Connection:Keep-Alive
Content-Length:21
Content-Type:text/html; charset=UTF-8
I am not able to understand why my original request is not sending. I have allowed all origins from my server side (Access-Control-Allow-Origin:*). Please help, Thanks in advance
Edit: The problem is "real request is not sending" after preflight(OPITONS) request is complete.