Skip to content

fix: allow to run tasks via nitro cli#4188

Merged
pi0 merged 2 commits intonitrojs:mainfrom
jkniest:fix/tasks-via-cli
Apr 13, 2026
Merged

fix: allow to run tasks via nitro cli#4188
pi0 merged 2 commits intonitrojs:mainfrom
jkniest:fix/tasks-via-cli

Conversation

@jkniest
Copy link
Copy Markdown
Contributor

@jkniest jkniest commented Apr 7, 2026

🔗 Linked issue

Resolves #4187

❓ 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

In the current beta version and main branch it is not possible to run tasks via the CLI, e.g.: npx nitro task run example (doesn't matter which package manager you use).

The CLI runs the command using POST, while on the Dev Server only GET is registered, so it doesn't work. I've just added a POST method as well (using the same business logic). In my eyes if makes sense aswell, since executing Tasks is doing something which I would classify more under POST.

Before:
CleanShot 2026-04-07 at 14 12 35@2x

Reproduction is available here: https://stackblitz.com/edit/github-wtbduyfz?file=README.md

When the dev server runs, open a second terminal as seen in the screenshot and try to run the example command.

📝 Checklist

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

@jkniest jkniest requested a review from pi0 as a code owner April 7, 2026 12:17
@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 7, 2026

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

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 7, 2026

📝 Walkthrough

Walkthrough

Added a shared task handler and POST route for dev tasks at /_nitro/tasks/:name; handler parses JSON body with safe fallback, merges query params with body.payload when present (or full body), and invokes runTask with event.req.waitUntil and the route name. Also added tests covering listing and executing tasks.

Changes

Cohort / File(s) Summary
Dev Tasks Route Refactoring
src/runtime/internal/routes/dev-tasks.ts
Added shared taskHandler(event: H3Event); registered both GET and POST for /_nitro/tasks/:name; changed body parsing to JSON with fallback {} and payload merge to prefer body.payload when present; passes event.req.waitUntil and name to runTask.
Tests: Nitro Dev Tasks
test/presets/nitro-dev.test.ts
Added describe("tasks") suite: tests for GET /_nitro/tasks listing, GET and POST /_nitro/tasks/:name execution, payload via POST body, and payload via query string.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Title check ⚠️ Warning The title contains a typo ('alow' instead of 'allow') and follows conventional commits format with 'fix:' prefix, but the typographical error compromises clarity. Correct the typo to 'fix: allow to run tasks via nitro cli' to ensure the title is clear and professional.
✅ Passed checks (2 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description check ✅ Passed The PR description clearly explains the issue (CLI uses POST, dev server only registered GET), the fix (adding POST handler), and provides reproduction steps with a screenshot.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@parallax1s
Copy link
Copy Markdown

I checked this against #4187 and the direction looks right:

  • CLI uses POST
  • dev route now accepts POST for /_nitro/tasks/:name

I also like the shared handler and the body.payload ?? body merge, which aligns with the tasks docs shape.

One request before merge: can we add a regression test that runs nitro task run <name> against a running dev server, so this doesn’t regress again?

@pi0 pi0 changed the title fix: Allow to run tasks via CLI again fix: alow to run tasks via nitro cli Apr 13, 2026
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.

thnx!

@pi0 pi0 merged commit 551d8c0 into nitrojs:main Apr 13, 2026
7 of 8 checks passed
@jkniest jkniest changed the title fix: alow to run tasks via nitro cli fix: allow to run tasks via nitro cli Apr 14, 2026
RihanArfan added a commit that referenced this pull request Apr 16, 2026
Co-authored-by: Rihan Arfan <me@file.properties>
@coderabbitai coderabbitai Bot mentioned this pull request Apr 16, 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.

Tasks can't run on the CLI in dev mode

4 participants