Skip to content

feat: custom path for standalone adapter #5078

@mjomble

Description

@mjomble

Describe the feature you'd like to request

Allow serving tRPC from a non-root path (e.g. localhost:3000/trpc or localhost:3000/api) when using the standalone adapter.

Describe the solution you'd like to see

A new createHTTPServer option, for example:

createHTTPServer({
  router: appRouter,
  basePath: '/api', // or maybe '/api/' or 'api/'?
})

Describe alternate solutions

Clarifying in the documentation that the standalone adapter can only be served at the root path and that alternatively, one can use @trpc/server/adapters/node-http, calculate the path from req and pass it on to nodeHTTPRequestHandler().

Adding a new option to the standalone adapter seems more user-friendly, though.

Additional information

I might be able to implement the new option in a PR, if we decide on the exact format and behavior in terms of leading and trailing slashes.

See also: #4059

👨‍👧‍👦 Contributing

  • 🙋‍♂️ Yes, I'd be down to file a PR implementing this feature!

Metadata

Metadata

Assignees

No one assigned

    Labels

    ✅ accepted-PRs-welcomeFeature proposal is accepted and ready to work on

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions