How to enable Google Cloud kubernetes CORS?


#1

I’m serving my static pages from Firebase.
I have an API service running on GKE cloud.

Both of the services under the same domain (example.com and api.example.com),
and use the same protocol (https).

When I try to access the api.example.com I get access-control-allow-origin rejection.
How can I configure GKE to enable CORS from the same domain?


#2

If you want to enable CORS at the ingress level you can do so within the spec using annotations.

If you are referring only to firebase (though I don’t see the relation to GKE) then you need to tell your express app to use CORS:

app.use((req, res, next) => {

    res.setHeader('Access-Control-Allow-Origin', '*');
    res.setHeader('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
    res.setHeader('Access-control-Allow-Headers', 'Content-Type,Authorization');

    next();

});