Next.js Discord

Discord Forum

Is it possible to have Vercel cron call my custom domain (canonical URL) instead of the vercel URL?

Unanswered
IPJT posted this in #help-forum
Open in Discord
Vercel cron jobs will trigger your functions by calling the Vercel auto-assigned URL. Is it possible to make it call my custom domain instead?

3 Replies

Western paper wasp
Vercel Cron jobs: https://vercel.com/docs/cron-jobs

Vercel environment variables (including system variables such as VERCEL_URL): https://vercel.com/docs/projects/environment-variables/system-environment-variables

Domains / Custom domains: https://vercel.com/docs/projects/domains

If you really need to call a custom domain, move the schedule outside (GitHub Actions, Cloudflare Cron, UptimeRobot, or any cron) and pull https://yourdomain.com/api/....
If the task is to “know the canonical domain inside the handler,” then focus on the host / x-forwarded-host headers, or store the canonical domain in ENV and use it in the logic

p.s. maybe someone here can suggest something else
Thanks @Western paper wasp !
I've leaked some vercel auto-assigned URLs to users. I've fixed the leak but due to users having saved these URLs as bookmarks etc. I'd like to have all Vercel URLs redirect to the canonical URL (my custom domain) such that they do not end up on old deployments.

I've done so using Vercel Firewall, which works fine. Only problem is that it breaks my Vercel-cronjobs as they are redirected to my-domain.com (without /api/...)
Western paper wasp
Vercel Cron always calls Vercel URLs, as far as I know, and this cannot be changed. If all Vercel URLs redirect to a custom domain and this breaks cron, there are two options:
1. Exclude cron requests from the redirect (by user-agent/path /api/* or x-vercel-cron headers).
2. Move cron outside (GitHub Actions, Cloudflare Cron, UptimeRobot) and pull https://my-domain.com/api/....
To determine the canonical domain inside the handler, use host or x-forwarded-host, or store the domain in env.