I've just deployed a node.js - vue.2.0 app to Google Cloud .
The vue.js 2.0 app is inside of the public node directory . Everything runs fine, except that all my queries to the web services are failing , inside of the habitual app.js node file, you know .. There are not calls to any other node server, that is why i even have tried localhost:8080 as a server name.
https://cedar-network-259109.appspot.com
All back end queries done from the app are failing :
POST
http://localhost:8080/getUsers
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:8080/getUsers. (Reason: CORS request did not succeed).
I've also managed the app to call the google cloud server url : same error .
POST http://cedar-network-259109.appspot.com:8080/getUsers
It doesnt work neither.
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:8080/getUsers. (Reason: CORS request did not succeed).
This app is correctly working when deployed on openode.io host : http://vue-starter-webpack-cli-4-node.openode.io/.
MongoDb Atlas is connected (0.0.0.0 wildcard).
QUESTION : Do I have to configure cors on my google cloud app with this doc , using the strange command? :
https://cloud.google.com/storage/docs/configuring-cors
Thanks a lot !
EDIT : This is what I got when asking about my cors config, it looks like I haven't got any cors config ? :
C:\UwAmp\www\vue-starter-webpack-cli-4-node-gcloud>gsutil cors get gs://cedar-network-259109.appspot.com
gs://cedar-network-259109.appspot.com/ has no CORS configuration.
EDIT 2 :
I'm sending a CORS params to my google cloud app like this :
>gsutil cors set cors-json-file.json gs://cedar-network-259109.appspot.com
This is my cors-json-file.json file :
[
{
"origin": ["https://cedar-network-259109.appspot.com"],
"responseHeader": ["Content-Type"],
"method": ["GET", "POST","HEAD", "DELETE"],
"maxAgeSeconds": 3600
},
{
"origin": ["https://cedar-network-259109.appspot.com:8080"],
"responseHeader": ["Content-Type"],
"method": ["GET", "POST","HEAD", "DELETE"],
"maxAgeSeconds": 3600
}
]
There is still an error :
POST https://cedar-network-259109.appspot.com:8080/getUsers
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://cedar-network-259109.appspot.com:8080/getUsers. (Reason: CORS request did not succeed).
There are my informations :
>gsutil cors get gs://cedar-network-259109.appspot.com
[{"maxAgeSeconds": 3600, "method": ["GET", "POST", "HEAD", "DELETE"], "origin": ["https://cedar-network-259109.appspot.com:8080"], "responseHeader": ["Content-Type"]}]
And my Request URL:https://cedar-network-259109.appspot.com:8080/getUsers headers :
Host: cedar-network-259109.appspot.com:8080
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:68.0) Gecko/20100101 Firefox/68.0
Accept: application/json, text/plain, */*
Accept-Language: fr,en-US;q=0.7,en;q=0.3
Accept-Encoding: gzip, deflate, br
Referer: https://cedar-network-259109.appspot.com/
Origin: https://cedar-network-259109.appspot.com
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
Content-Length: 0
My app.yaml file :
runtime: nodejs
env: flex
manual_scaling:
instances: 1
resources:
cpu: 1
memory_gb: 0.5
disk_size_gb: 10
EDIT 3 : Modified my node app.js backend with this code :
const cors = require("cors");
app.use(
require("cors")({
origin: function(origin, callback) {
callback(null, origin);
},
credentials: true
})
);
to this :
app.use(
require("cors")({
origin: "https://cedar-network-259109.appspot.com",
credentials: true
})
);
With no luck ! Please help me !