Skip to content

presets(vercel): integrate with scheduled tasks#4030

Merged
pi0 merged 9 commits into
nitrojs:mainfrom
RihanArfan:feat/vercel-cron
Feb 13, 2026
Merged

presets(vercel): integrate with scheduled tasks#4030
pi0 merged 9 commits into
nitrojs:mainfrom
RihanArfan:feat/vercel-cron

Conversation

@RihanArfan
Copy link
Copy Markdown
Member

🔗 Linked issue

Related #1974 - we should update the checklist

❓ Type of change

  • 📖 Documentation (updates to the documentation, readme, or JSdoc annotations)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • 👌 Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

📚 Description

Support Vercel Cron within Nitro Tasks. Automatically creates Vercel Cron configuration based on Nitro scheduled tasks, so fully zero-config when deploying to Vercel.

📝 Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@vercel
Copy link
Copy Markdown

vercel Bot commented Feb 12, 2026

@RihanArfan is attempting to deploy a commit to the Nitro Team on Vercel.

A member of the Team first needs to authorize it.

@RihanArfan RihanArfan marked this pull request as ready for review February 12, 2026 15:01
@RihanArfan RihanArfan requested a review from pi0 as a code owner February 12, 2026 15:01
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Feb 12, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Implements Vercel Cron Jobs support for Nitro by introducing a new cron handler route, handler logic with optional CRON_SECRET validation, and configuration updates. Includes supporting documentation and test coverage for the new scheduled tasks integration.

Changes

Cohort / File(s) Summary
Documentation
docs/1.docs/50.tasks.md, docs/2.deploy/20.providers/vercel.md
Added Vercel Cron Jobs documentation with code samples, wording corrections, and details on native integration and CRON_SECRET-based endpoint security.
Vercel Preset Types
src/presets/vercel/types.ts
Added optional cronHandlerRoute property to VercelOptions interface with default value "/_vercel/cron".
Vercel Preset Runtime
src/presets/vercel/preset.ts, src/presets/vercel/runtime/cron-handler.ts, src/presets/vercel/utils.ts
Implemented cron handler route with Bearer token validation via timingSafeEqual, x-vercel-cron-schedule header validation, and invocation of scheduled tasks. Integrated cron task registration into preset build logic and configuration generation.
Tests
test/presets/vercel.test.ts
Added cron entry to web preset configuration, corresponding route mapping, and function list entry for verification.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 3 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The PR title 'presets(vercel): integrate with scheduled tasks' follows conventional commits format with type 'presets', scope 'vercel', and a clear description of the integration work.
Description check ✅ Passed The PR description directly relates to the changeset, explaining the addition of Vercel Cron support within Nitro Tasks with automatic configuration generation for zero-config deployment.
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into main

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

No actionable comments were generated in the recent review. 🎉


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@src/presets/vercel/runtime/cron-handler.ts`:
- Line 9: The current check if (authHeader !== `Bearer ${cronSecret}`) leaks
timing information; replace it with a constant-time comparison using Node's
crypto.timingSafeEqual: normalize both sides to Buffers of equal length (e.g.,
compute a safe HMAC or hash of `authHeader` and `Bearer ${cronSecret}` or
zero-pad lengths) and use timingSafeEqual to compare, updating the validation
logic in the cron handler that reads authHeader and cronSecret so the handler
performs a constant-time comparison before accepting the request.
🧹 Nitpick comments (1)
docs/2.deploy/20.providers/vercel.md (1)

116-121: Consider adding a warning that the endpoint is unprotected when CRON_SECRET is not set.

Currently, the cron handler (in cron-handler.ts) only validates the Authorization header when CRON_SECRET is set. If a user doesn't configure it, the /_nitro/tasks/vercel endpoint is publicly accessible. A brief warning here would help users avoid accidentally deploying an unprotected cron endpoint.

Comment thread src/presets/vercel/runtime/cron-handler.ts Outdated
@pi0 pi0 changed the title feat(tasks): support vercel cron presets(vercel): integrate with scheduled tasks Feb 12, 2026
Comment thread src/presets/vercel/runtime/cron-handler.ts Outdated
Comment thread src/presets/vercel/preset.ts Outdated
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Feb 13, 2026

Open in StackBlitz

npm i https://pkg.pr.new/nitrojs/nitro@4030

commit: 9e7e37c

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@src/presets/vercel/runtime/cron-handler.ts`:
- Around line 18-21: The handler currently checks
event.req.headers.get("x-vercel-cron-schedule") (variable cron) and throws an
HTTPError when missing; Vercel does not send that header so the handler will
always 400 in production—replace reliance on that header by reading a schedule
identifier from the request path or query string (e.g., parse event.req.url or
use event.req.nextUrl.searchParams.get("scheduleId") or distinct endpoints per
schedule), fall back to validating User-Agent ("vercel-cron/1.0") and the
Authorization bearer token if needed, and remove the HTTPError throw that
assumes the header exists; update any references to cron variable accordingly
(e.g., in the function that dispatches cron tasks) so scheduleId is used
instead.
🧹 Nitpick comments (2)
src/presets/vercel/runtime/cron-handler.ts (1)

5-16: CRON_SECRET validation is optional — consider the security implication.

When CRON_SECRET is not set, the cron endpoint is completely unprotected and publicly accessible. Anyone can trigger scheduled tasks by sending a request with a valid x-vercel-cron-schedule header. While this matches Vercel's own docs (CRON_SECRET is opt-in), consider logging a warning during build if CRON_SECRET is not configured, or at minimum note this in the documentation.

src/presets/vercel/preset.ts (1)

22-25: Consider logging when cron handler is registered.

Other configuration steps in this hook log info messages (e.g., runtime, entry format). Adding a similar log for cron handler registration would improve build-time observability.

📝 Suggested addition (inside the cron tasks block, after pushing the handler)
         nitro.options.handlers.push({
           route: nitro.options.vercel!.cronHandlerPath!,
           lazy: true,
           handler: join(presetsDir, "vercel/runtime/cron-handler"),
         });
+        logger.info(`Registered cron handler at \`${nitro.options.vercel!.cronHandlerPath!}\`.`);

Based on learnings: "Use consola for logging in build/dev code; use nitro.logger when available"

Comment thread src/presets/vercel/runtime/cron-handler.ts
Comment thread src/build/rollup/prod.ts Outdated
},
});

return { cron, tasks: result };
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this object consumed by vercel? Why this specific shape?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No particular reason. I've double checked and Vercel only shows things that were logged but not the response of this endpoint, so I'll update it so we return nothing. Should we log anything? Like Running cron schedule * * * * *

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We mighjt like success: true for example. My main concern is to not introduce a reponse and break it later only

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorted

Comment thread src/presets/vercel/preset.ts Outdated
Comment thread src/presets/vercel/types.ts Outdated
Copy link
Copy Markdown
Member

@pi0 pi0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! 🚀

@pi0 pi0 merged commit f663e76 into nitrojs:main Feb 13, 2026
10 of 11 checks passed
@coderabbitai coderabbitai Bot mentioned this pull request Mar 30, 2026
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants