firebase:hosting

Firebase: Hosting #

Cloudflare DNS Setup #

When adding a custom domain for a website deployed with Firebase (SSG) the following points should be taken into account:

  • Firebase requires setting a TXT record in the DNS records to verify the domain ownership. This value must be present even after the initial verification, as long as the (sub)domain proxy is in use.
  • According to the docs, after the initial (unsuccessful) verification attempt, Firebase will not automatically retry verifying the domain, so we need to manually trigger a retry from the Firebase web console.
  • After a custom domain name is added, the site must be re-deployed to become available at the newly added address.

When using Cloudflare DNS:

  • When redirecting to *.web.app (as opposed to an IP address), we must set a CNAME record (not the A type record).
  • It is better to disable the “proxy” option at first. Doing this can help to verify and debug the site availablity under the new domain name.

Enabling Cloudflare Proxy #

Once the new deployment becomes available at the new address, the proxy option can be enabled to take advantage of Cloudflare CDN.

Enabling “proxy” could make the page unaccessible (see [0], [1]). If in DevTools->Network the error status is NS_ERROR_REDIRECT_LOOP, the issue is likely related to SSL/TLS. Under the default Cloudflare SSL/TLS configuration, Cloudflare tries to fetch the original page over HTTP (not HTTPS) which would start a DNS lookup loop.

This can be fixed by changing SSL/TLS mode for the domain from “Flexible” (default) to “Full” or “Full (Strict)”. After this change, instead of HTTP requests Cloudflare would send HTTPS to the origin servers.