I am trying to create a head request on a link generated using Firebase Functions using getSignedURL method.
I want to check if the URL is still alive and is not expired for that I am
And for cors I used gsutils from cloud shell on cloud.google.com and setup the cors:
gsutil cors set cors.json gs://mybucket.appspot.com
Setting CORS on gs://mybucket.appspot.com/...
di@cloudshell:~ (ecutter-web)$ gsutil cors get gs://mybucket.appspot.com
[{"maxAgeSeconds": 300, "method": ["HEAD"], "origin": ["https://myapp.web.app"],
"responseHeader": ["Access-Control-Allow-Origin"]}]
but when I make a head request to that URL it shows error :
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://storage.googleapis.com/myapp.appspot.com/public/myfile.doc?GoogleAccessId=firebase-adminsdk-7u2d7%40myapp.iam.gserviceaccount.com&Expires=1603783901&Signature=... (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).
this is the cors.json:
[
{
"origin": ["https://myapp.web.app"],
"method": ["HEAD"],
"responseHeader": ["Access-Control-Allow-Origin"],
"maxAgeSeconds": 300
}
]
original appname is replaced with myapp.
and function to check the validity :
function loadhandle() {
console.log('logging');
console.log(this.responseText);
}
function checkUrl(s) {
console.log('creating request');
var xml = new XMLHttpRequest();
xml.addEventListener("load", loadhandle, false);
xml.open("HEAD", s);
xml.send();
}
Where is the problem?