Custom Mapped Domain & CORS issue

I create on Cloud Run a project to complete the facebook server tracking on the https://www.runayaq.com website.

I used this URL for the debug server, not a custom one:

I created a custom domain just for the production server with the Custom Mapped Domain, i didn’t to use the Load Balancer

I saw these issues on the console browser:

related to CORS

Is it my set up correct ? why is this CORS issue happening ?

Hi @FreddyEE,

Cross-Origin Resource Sharing (CORS) is a security mechanism in web browsers that prevents websites from making requests to different domains than the one they originated from. This is a security feature to protect users from malicious websites.

Let’s break down the issues you’re encountering.

Understanding the Issues.

  • CORS Policy Block: This means your browser is preventing your website from making requests to your Cloud Run server. This is a security feature designed to protect your site from malicious requests.
  • ERR_FAILED 503 (Service unavailable): This usually means your Cloud Run service isn’t responding properly. It could be down, overloaded, or encountering an internal error.
  • XHR failed loading: This is a general error that could be caused by a network issue, a problem with the server, even a browser issue or connected to CORS issue.

Key Considerations.

Troubleshooting and Solutions.

1. CORS Configuration

  • Add CORS Headers: Configure your Cloud Run service to add appropriate Cross-Origin Resource Sharing (CORS) headers. Here’s how:
  • Cloud Functions (if applicable): In your Cloud Function, add the following to the response object before sending it back: Access-Control-Allow-Origin and Access-Control-Allow-Method.
  • Cloud Run Service (if applicable): Use gcloud beta run deploy to add CORS headers: --update-env-vars
  • Container Image: Include a web server that sets CORS headers in your container image (e.g., Express.js, Flask).
  • Verify CORS Headers: Use browser developer tools (Network tab) to see if your Cloud Run service is sending the correct CORS headers.

2. Custom Domain Setup

  • DNS Configuration: Make sure your custom domain is correctly pointing to your Cloud Run service. You’ll need to create a CNAME record in your DNS settings.
  • HTTPS/SSL: Ensure that your custom domain is using a valid SSL certificate. This is crucial for secure communication.

3. Cloud Run Troubleshooting

  • Logs: Review your Cloud Run logs (in the Google Cloud console) for error messages that can give you clues about the problem.
  • Health Checks: Check your Cloud Run service’s health checks to ensure it’s responding as expected.
  • Deployment: Double-check that you’ve deployed the correct version of your code to your Cloud Run service.
  • Resource Limits: If your Cloud Run service is experiencing high traffic, consider adjusting its resource limits (memory, CPU) to prevent overloading.

Additional Tips

  • Debugging Tools: Use browser developer tools (Network tab) to inspect requests and responses to pinpoint the source of the issue.
  • Network Tests: Use tools like curl or wget to test requests to your Cloud Run service directly.

I hope the above information is helpful.

1 Like

Excuse my ignorance, so a solution could be using a docker image or what could be more efficient ?