Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Containerized FastAPI app using Uvicorn serving JS & CSS assets over HTTP

Cloud Run is properly serving my application over HTTPS, but the JS & CSS assets are being loaded via HTTP so the browser blocks them.

I include the assets like so:

<script src="[[ url_for('static', path='/js/bundle.js') ]]"></script>

In my Dockerfile I have:

CMD ["uvicorn", "main:app", "--proxy-headers", "--host", "0.0.0.0", "--port", "8000"]

which as I understand is the solution but the issue persists.

0 1 954
1 REPLY 1

Hi @tim-snyder-wust,

Welcome to Google Cloud Community!

The issue of your browser blocking JS & CSS assets served over HTTP on your Cloud Run application can be solved by:

  1. Updating URL construction to statically define asset URLs.
  2. Configuring Uvicorn for HTTPS by explicitly specifying the HTTPS port and providing SSL certificate and key files.
  3. Serving static files with a separate server like NGINX or Apache.
  4. Checking your Cloud Run configuration for SSL certificates, domain mappings, and static file serving settings.

Make sure your Cloud Run service exposes port 443 and clear your browser cache to ensure it fetches latest configurations.

Top Solution Authors