-1

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).

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 !

harmonius cool
  • 337
  • 1
  • 2
  • 23

1 Answers1

0

If the resources you are trying to access are stored on Google Cloud Storage then you'll need to enable CORS as explained on the documentation you mention. If the resources you are trying to access files hosted by another Google App Engine app you need to modify your app.yaml file as explained on the documentation.

Daniel Ocando
  • 3,554
  • 2
  • 11
  • 19
  • No, the node.js backend app.js is on the same unique google app, connecting to mongodb atlas. – harmonius cool Nov 19 '19 at 16:06
  • I would appreciate if somebody could help me. Do I have to modify app.yaml ? – harmonius cool Nov 19 '19 at 16:52
  • If you are not trying to access the files form another Google App Engine application you don't need to modify the app.yaml file. You are going to need to set the `Access-Control-Allow-Origin` HTTP header within your application. If you are looking for some code samples you can check this other posts [1](https://stackoverflow.com/questions/11001817/allow-cors-rest-request-to-a-express-node-js-application-on-heroku) or [2](https://stackoverflow.com/questions/57958849/how-to-fix-cors-node-js-on-google-app-engine). – Daniel Ocando Nov 19 '19 at 21:06
  • Thanks a lot, lets try this ! – harmonius cool Nov 20 '19 at 12:35