1
votes

I'm trying to deploy an Angular app to a Google Cloud Storage bucket so that I can serve the app from there. The bucket has public access and is named so that I can serve it as a custom website via CNAME (let's say test.example.com). The bucket is also configured to map the main page to index.html and the 404 handler to index.html. When loading https://test.example.com, most of the app loads fine, but any of the assets that are loaded via XHR (GET from /assets/) get an HTTP 401 error. There are no preflight requests. I've tried setting various permutations of CORS settings on the bucket, but nothing seems to help.

I am getting this on loading on assets.

<?xml version='1.0' encoding='UTF-8'?><Error><Code>AuthenticationRequired</Code><Message>Authentication required.</Message></Error>

Can anyone help me out.

We are using Google Cloud Storage and Google DNS Hosting for this.

Below link is for reference: https://html.developreference.com/article/10228923/401+error+with+Angular+app+deployed+to+Google+Cloud+Storage+with+CNAME%27d+DNS

1
Could you see any error logs in Cloud Stackdriver Logging? - Nibrass H
@NibrassH nothing there and not need of log. - Rakshit Patel

1 Answers

1
votes

Any request your application sends to the Cloud Storage JSON API that requires authorization needs to identify your application to Google.

You can identify your application by 2 ways:

  • Using an OAuth 2.0 token (which also authorizes the request)

  • Using the application's API key

Please follow the steps in the Documentation linked above to use whether Oauth 2.0 token or API key.

Let me know if it works for you.