Skip to content

feat(server): custom base path for requests in standalone adapter#6454

Merged
trpc-bot merged 11 commits into
nextfrom
issues/5078-custom-path
Feb 6, 2025
Merged

feat(server): custom base path for requests in standalone adapter#6454
trpc-bot merged 11 commits into
nextfrom
issues/5078-custom-path

Conversation

@KATT

@KATT KATT commented Feb 6, 2025

Copy link
Copy Markdown
Member

Closes #5078

🎯 Changes

What changes are made in this PR? Is it a feature or a bug fix?

βœ… Checklist

  • I have followed the steps listed in the Contributing guide.
  • If necessary, I have added documentation related to the changes made.
  • I have added or updated the tests related to the changes made.

Summary by CodeRabbit

  • New Features

    • Introduced customizable request path handling via a new configuration option for HTTP and HTTP/2 handlers.
    • Updated API endpoint behavior to return structured URL data for improved response consistency.
  • Documentation

    • Enhanced migration guides and integration instructions to detail the new custom path option and server setup.
    • Updated documentation to clarify configuration changes and compatibility requirements.

@coderabbitai

coderabbitai Bot commented Feb 6, 2025

Copy link
Copy Markdown
Contributor

Warning

Rate limit exceeded

@KATT has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 0 minutes and 1 seconds before requesting another review.

βŒ› How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between 3d2a4ca and ec2aac6.

πŸ“’ Files selected for processing (4)
  • packages/server/src/adapters/standalone.ts (3 hunks)
  • packages/tests/server/adapters/standalone.http2.test.ts (5 hunks)
  • www/docs/migration/migrate-from-v10-to-v11.mdx (1 hunks)
  • www/docs/server/adapters/standalone.md (4 hunks)

Walkthrough

The pull request refactors type definitions and updates functions across both HTTP and HTTP2 adapters to support a configurable request pathname. The changes include restructuring the NodeHTTPRequestHandlerOptions, introducing a new StandaloneHandlerOptions with an optional pathname property, updating tests to reflect API and naming changes, and revising documentation to explain the custom path capability for the standalone adapter.

Changes

Files Change Summary
packages/server/src/adapters/node-http/types.ts Refactored the NodeHTTPRequestHandlerOptions type to extend NodeHTTPHandlerOptions explicitly; added a new path property with examples in comments.
packages/server/src/adapters/standalone.ts Introduced a new StandaloneHandlerOptions type with an optional pathname property; updated handler options for both HTTP and HTTP2 to accommodate the custom path feature.
packages/tests/.../standalone.http2.test.ts Renamed the procedure from hello to status; replaced httpBatchLink with httpLink; added tests for custom path behavior including handling of undefined paths (404 responses) and verifying updated handler functionality.
www/docs/.../migrate-from-v10-to-v11.mdx and www/docs/server/adapters/standalone.md Updated documentation to include details on the custom pathname option for the standalone adapter; reorganized examples and sections to reflect new server adapter usage and migration changes.

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant HTTPServer
  participant Handler
  participant Router

  Client->>HTTPServer: Send request with URL
  HTTPServer->>Handler: Forward request
  alt URL matches custom pathname
    Handler->>Router: Process request
    Router-->>Handler: Return response data
    Handler-->>HTTPServer: Send success response
  else URL does not match
    Handler-->>HTTPServer: Send 404 error
  end
  HTTPServer-->>Client: Deliver response
Loading

Assessment against linked issues

Objective Addressed Explanation
Custom path option for standalone adapter (#5078) βœ…

Poem

I'm a happy rabbit, hopping free,
In a code garden full of creativity.
A custom path now lights my way,
Guiding requests in a brand new day.
With each change, I cheer and playβ€”
Code carrots bring joy, hip-hip-hooray!
πŸ₯•πŸ‡


πŸͺ§ Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@railway-app

railway-app Bot commented Feb 6, 2025

Copy link
Copy Markdown

πŸš… Previously deployed to Railway in the trpc-sse-and-websockets project. Environment has been deleted.

@vercel

vercel Bot commented Feb 6, 2025

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for Git β†—οΈŽ

Name Status Preview Comments Updated (UTC)
next-prisma-starter βœ… Ready (Inspect) Visit Preview Feb 6, 2025 11:03am
og-image βœ… Ready (Inspect) Visit Preview πŸ’¬ Add feedback Feb 6, 2025 11:03am
www βœ… Ready (Inspect) Visit Preview πŸ’¬ Add feedback Feb 6, 2025 11:03am

@pkg-pr-new

pkg-pr-new Bot commented Feb 6, 2025

Copy link
Copy Markdown

Open in Stackblitz

npm i https://pkg.pr.new/trpc/trpc/@trpc/client@6454
npm i https://pkg.pr.new/trpc/trpc/@trpc/next@6454
npm i https://pkg.pr.new/trpc/trpc/@trpc/server@6454
npm i https://pkg.pr.new/trpc/trpc/@trpc/react-query@6454

commit: ec2aac6

@KATT KATT changed the title Issues/5078 custom path feat(server): custom pathname for requests in standalone adapter Feb 6, 2025
@KATT KATT marked this pull request as ready for review February 6, 2025 10:44
@KATT KATT requested review from a team as code owners February 6, 2025 10:44

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (3)
packages/server/src/adapters/standalone.ts (1)

62-70: Consider handling trailing slash edge case.

The implementation correctly handles the pathname slicing, but it might be good to handle the case where users forget to include the trailing slash.

-  const sliceLength = opts.pathname?.length ?? 1;
+  const pathname = opts.pathname?.endsWith('/') ? opts.pathname : `${opts.pathname}/`;
+  const sliceLength = pathname?.length ?? 1;
www/docs/server/adapters/standalone.md (1)

138-138: Fix grammar in heading.

Change "an Custom HTTP server" to "a Custom HTTP server".

-## Adding a handler to an Custom HTTP server
+## Adding a handler to a Custom HTTP server
🧰 Tools
πŸͺ› LanguageTool

[misspelling] ~138-~138: Use β€œa” instead of β€˜an’ if the following word doesn’t start with a vowel sound, e.g.Β β€˜a sentence’, β€˜a university’.
Context: ...ver (see below) ## Adding a handler to an Custom HTTP server createHTTPServer ...

(EN_A_VS_AN)

www/docs/migration/migrate-from-v10-to-v11.mdx (1)

27-32: Improve Section Title and Clarify Behavior for Custom pathname Option

The new section clearly documents the addition of the custom pathname option for the standalone adapter. However, the section title wording ("Custom pathname to handle requests under in the standalone adapter") is a bit awkward. Consider rephrasing it for clarity. For example, change it to:

-### Custom `pathname` to handle requests under in the standalone adapter (non-breaking)
+### Custom `pathname` option for standalone adapter (non-breaking)

Additionally, while the description ("The standalone adapter now supports a pathname option, which will slice the pathname from the beginning of the request path.") is clear, it might be helpful to briefly explain what "slicing" means in practice or include a reference to an example (if not already covered in the linked docs).

πŸ“œ Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between df313f4 and 3d2a4ca.

πŸ“’ Files selected for processing (5)
  • packages/server/src/adapters/node-http/types.ts (1 hunks)
  • packages/server/src/adapters/standalone.ts (3 hunks)
  • packages/tests/server/adapters/standalone.http2.test.ts (5 hunks)
  • www/docs/migration/migrate-from-v10-to-v11.mdx (1 hunks)
  • www/docs/server/adapters/standalone.md (4 hunks)
🧰 Additional context used
πŸͺ› LanguageTool
www/docs/server/adapters/standalone.md

[misspelling] ~138-~138: Use β€œa” instead of β€˜an’ if the following word doesn’t start with a vowel sound, e.g.Β β€˜a sentence’, β€˜a university’.
Context: ...ver (see below) ## Adding a handler to an Custom HTTP server createHTTPServer ...

(EN_A_VS_AN)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: E2E-tests (tanstack-start)
πŸ”‡ Additional comments (4)
packages/server/src/adapters/standalone.ts (1)

30-44: LGTM! Well-documented type definition.

The StandaloneHandlerOptions type is well-structured with clear documentation, examples, and default value specification.

packages/server/src/adapters/node-http/types.ts (1)

107-119: LGTM! Clean type restructuring.

The type extension is well-organized and the path property is properly documented.

packages/tests/server/adapters/standalone.http2.test.ts (1)

179-218: LGTM! Comprehensive test coverage for custom pathname.

The test case thoroughly verifies:

  1. 404 handling for undefined paths
  2. Correct URL construction with custom pathname
  3. Proper request handling under the custom path
www/docs/server/adapters/standalone.md (1)

164-187: LGTM! Clear documentation for custom pathname feature.

The documentation clearly explains the pathname feature with a practical example.

@github-actions

github-actions Bot commented Feb 7, 2025

Copy link
Copy Markdown
Contributor

This pull request has been locked because we are very unlikely to see comments on closed issues. If you think, this PR is still necessary, create a new one with the same branch. Thank you.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Feb 7, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: custom path for standalone adapter

2 participants