Astro, Cloudflare Pages, and Non-Trailing Slash Canonical URLs

A bit of a head-scratcher with Astro and Cloudflare Pages, but I think I've found a solution.