Repository navigation
refactor(task): use http.request - #3268
Conversation
pi0
left a comment
There was a problem hiding this comment.
Thanks ❤️
I have not tested PR and fetching socket is acually possible in Node, Deno and Bun but it can get buggy so we need to move away from it. Your code in PR would be a good start!
|
@pi0 is attempting to deploy a commit to the Nitro Team on Vercel. A member of the Team first needs to authorize it. |
📝 WalkthroughWalkthroughReplaces ofetch-based devFetch implementation with a native HTTP-based approach using Node's http module to properly support Unix socket paths and custom ports for dev server communication in task CLI commands. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
http.request to support socketPath in dev fetchhttp.request
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (2)
src/task.ts (2)
60-61: LGTM! Consider adding a clarifying comment.The baseURL construction is correct. When socketPath is provided, http.request uses it for the connection while still using the URL for the HTTP request line and Host header. The defaults (localhost:3000) appear reasonable for a dev server.
Optionally, add a comment to clarify the dual usage:
+ // baseURL is used for HTTP headers and path; socketPath (if present) overrides host/port for the connection const baseURL = `http://${buildInfo.dev.workerAddress.host || "localhost"}:${buildInfo.dev.workerAddress.port || "3000"}`; const socketPath = buildInfo.dev.workerAddress.socketPath;
77-86: Consider adding a request timeout.The request setup is correct, but without a timeout, the request could hang indefinitely if the dev server is unresponsive.
Apply this diff to add a reasonable timeout:
const request = http.request( url, { socketPath, method: options?.method, + timeout: 30000, // 30 seconds headers: { Accept: "application/json", "Content-Type": "application/json", }, }, (response) => {
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/task.ts(2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
- GitHub Check: tests-rolldown (windows-latest)
- GitHub Check: tests-rollup (windows-latest)
- GitHub Check: tests-rollup (ubuntu-latest)
🔇 Additional comments (4)
src/task.ts (4)
1-1: LGTM!The new imports are appropriate for the http.request-based implementation and provide proper typing support.
Also applies to: 5-5, 7-9
63-70: LGTM!The function signature is well-designed with proper typing. The generic type parameter allows callers to specify the expected response type, and the options are appropriately typed and optional.
71-75: LGTM!The URL construction using ufo utilities is clean and correct, properly handling base path joining and query parameter encoding.
105-110: LGTM!The request finalization logic is correct: errors are caught, the body is properly serialized, and the request is ended. While setting a Content-Length header would be more explicit, it's optional in HTTP/1.1.
🔗 Linked issue
resolves #3264
❓ Type of change
📚 Description
Since
ofetchdoesn't supportsocketPath, this PR directly useshttp.request.The implementation is pretty simple and only handles
JSONresponses, but that should be enough since the task's response is required to beJSON.Otherwise, we'd need to use
undici'sAgentforsocketPathsupport, which would require addingundicias a dependency or bundling it—both options seem to add extra overhead in my opinion 🤔Looking forward to your feedback! ❤️
📝 Checklist