Cube.js: serverless-google - invoking Google Cloud Function API endpoint is blocked by CORS policy

Created on 21 Aug 2020  路  3Comments  路  Source: cube-js/cube.js

Problem

Hi Team,
I've followed the steps in the serverless-google guide
https://github.com/cube-js/cube.js/tree/master/packages/cubejs-serverless-google

Everything deployed fine in GCP which is great.

However, when invoking the API endpoint, the request blocked by a CORS policy:
Access to XMLHttpRequest at 'https://googlecloud-api-endpoint-example/cubejs-api/v1/load?query=query_string' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

Below is the client side code that i'm using to set up the request:
const API_URL ='https://googlecloud-api-endpoint-example' const cubejsApi = cubejs( 'API_TOKEN', { apiUrl: API_URL + '/cubejs-api/v1' } );

And this is my serverless.yml environment variable config:
environment: CUBEJS_DB_TYPE: bigquery CUBEJS_DB_BQ_PROJECT_ID: BQ_PROJECT_ID CUBEJS_DB_BQ_KEY_FILE: ./path/to/key/file REDIS_URL: https://REDIS_URL CUBEJS_API_SECRET: API_SECRET CUBEJS_APP: "${self:service.name}-${self:provider.stage}" CUBEJS_SERVERLESS_PLATFORM: "${self:provider.name}"

what should i be doing to stop the request being blocked by CORS?

question

All 3 comments

This works for AWS (haven't tested on GCP)

...
      - http:
          path: /{proxy+}
          method: ANY
          cors:
            origin: '*'
            headers:
              - Authorization
              - Content-Type
              - X-Amz-Date
              - X-Amz-Security-Token
              - X-Api-Key
              - X-Request-Id
...

perfect. thank you. I'll look into it and provide an update

Was this page helpful?
0 / 5 - 0 ratings