Hi everyone,
I feel like a newbie here but I'm trying to run a simple AJAX request from a browser to access a GCF and Chrome is reporting:
I've got a function called Authenticate (as shown above) that's using a bucket called:
I've used gsutil to set CORS using the following JSON file:
[{
"responseHeader": ["Content-Type"],
"method": ["GET", "HEAD", "DELETE", "OPTIONS"],
"maxAgeSeconds": 3600
}]
With the following command:
And then get the following output from the corresponding get command:
I'm using the default example code that's provided when you create a new function as stated below:
/**
* Responds to any HTTP request that can provide a "message" field in the body.
*
* @param {!Object} req Cloud Function request context.
* @param {!Object} res Cloud Function response context.
*/
exports.helloWorld = function helloWorld(req, res) {
// Example input: {"message": "Hello!"}
if (req.body.message === undefined) {
// This is an error case, as "message" is required.
res.status(200).send('No message defined!');
} else {
// Everything is okay.
console.log(req.body.message);
res.status(200).send(req.body.message);
}
};
And a simple HTML with the following Javascript:
$.ajax({
type: "POST",
data: {
message: 'Testing'
},
dataType: 'json',
success: function (response) {
console.log(response);
},
error: function (xhr, status) {
console.log(xhr);
}
});
Which is causing the error.
In my DEV console I can see the network request go through. Here are the HTTP Response Headers I'm getting are:
cache-control:private
content-encoding:gzip
content-length:27
content-type:text/html; charset=utf-8
date:Wed, 08 Feb 2017 03:45:50 GMT
etag:W/"7-274e639a"
function-execution-id:azc1zqfb1tq8
server:Google Frontend
status:200
vary:Accept-Encoding
x-cloud-trace-context:70e08d634a9644c32530326de0471a64;o=1
x-cloud-trace-context:70e08d634a9644c32530326de0471a64
x-powered-by:Express
I would have expected to see the Access-Control-Allow-Origin header within the Response Headers to indicate that it was allowing * but I'm definitely not seeing it.
The crazy thing though is that when I look at the Network item and click on Response I get:
Testing
Which suggests that all things being equal, it ACTUALLY ran!
I apologise if this has been answered before but I've searched for as many different keywords and nothing seems to have solved my problem. I thought a fresh pair of eyes on the issue (and some decent expertise) would help.
Thanks in advance!