This is a simple cloudflare worker to demonstrate that Planetscale ip restrictions need to include ipv6 support
- Create a cloudflare account (it's free)
- Checkout this code then run:
pnpm install
pnpm wrangler login- Get the database url for your Planetscale databse and save it as a secret:
pnpm wrangler secret put DATABASE_URL- Deploy the app:
pnpm deploy-
Open the preview url provided in your browser - you should see:
Success - was able to connect and query the database -
Add a Planetscale ip restriction rule with allow list from https://www.cloudflare.com/ips/
103.21.244.0/22, 103.22.200.0/22, 103.31.4.0/22, 104.16.0.0/13, 104.24.0.0/14, 108.162.192.0/18, 131.0.72.0/22, 141.101.64.0/18, 162.158.0.0/15, 172.64.0.0/13, 173.245.48.0/20, 188.114.96.0/20, 190.93.240.0/20, 197.234.240.0/22, 198.41.128.0/17 -
Refresh you browser and you should see:
Error - connection not allowed
Planetscale support did some testing and found this IP address is missing from the Cloudflare allow list:
104.16.0.0/12
Once that was added this app starts to work. The full IP allow list for Cloudflare should be:
103.21.244.0/22, 103.22.200.0/22, 103.31.4.0/22, 104.16.0.0/13,
104.24.0.0/14, 108.162.192.0/18, 131.0.72.0/22, 141.101.64.0/18,
162.158.0.0/15, 172.64.0.0/13, 173.245.48.0/20, 188.114.96.0/20,
190.93.240.0/20, 197.234.240.0/22, 198.41.128.0/17,
104.16.0.0/12