Skip to content

feat(server)!: reduce fetch handler bundle size#42

Merged
dinwwwh merged 11 commits into
mainfrom
feat/improve-fetch-handler
Dec 2, 2024
Merged

feat(server)!: reduce fetch handler bundle size#42
dinwwwh merged 11 commits into
mainfrom
feat/improve-fetch-handler

Conversation

@dinwwwh
Copy link
Copy Markdown
Member

@dinwwwh dinwwwh commented Dec 2, 2024

🚨 Breaking Changes Alert 🚨

We've revamped the Fetch handler APIs for a cleaner, more modular experience. Here's what you need to know:

What's Changed?

The new API lets you define handlers inline without global declarations. This simplifies your setup and keeps your bundle lightweight—especially useful for serverless environments.

import { createOpenAPIServerlessHandler } from '@orpc/openapi/fetch';
import { createORPCHandler, handleFetchRequest } from '@orpc/server/fetch';

export function fetch(request: Request) {
  return handleFetchRequest({
    router,
    request,
    prefix: '/api',
    context: {},
    handlers: [
      createORPCHandler(), 
      createOpenAPIServerlessHandler(), // Or use createOpenAPIServerHandler
    ],
  });
}

Key Benefits:

  • No Global Handler Declaration: Handlers are now scoped to the function where they're used.
  • Smaller Serverless Bundles: Bundle only the handlers you need for your use case.
  • Future-Ready: This lays the groundwork for upcoming big features (stay tuned!). 🚀

If you're upgrading, make sure to update your fetch handlers to use this new API format.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Dec 2, 2024

Open in Stackblitz

More templates

@orpc/client

npm i https://pkg.pr.new/@orpc/client@42

@orpc/openapi

npm i https://pkg.pr.new/@orpc/openapi@42

@orpc/react

npm i https://pkg.pr.new/@orpc/react@42

@orpc/contract

npm i https://pkg.pr.new/@orpc/contract@42

@orpc/server

npm i https://pkg.pr.new/@orpc/server@42

@orpc/shared

npm i https://pkg.pr.new/@orpc/shared@42

@orpc/transformer

npm i https://pkg.pr.new/@orpc/transformer@42

@orpc/zod

npm i https://pkg.pr.new/@orpc/zod@42

commit: c8f1c5e

@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented Dec 2, 2024

Deploying orpc with  Cloudflare Pages  Cloudflare Pages

Latest commit: c8f1c5e
Status: ✅  Deploy successful!
Preview URL: https://37fba079.orpc-1qh.pages.dev
Branch Preview URL: https://feat-improve-fetch-handler.orpc-1qh.pages.dev

View logs

@dinwwwh dinwwwh changed the title feat!: reduce fetch handler bundle size feat(server)!: reduce fetch handler bundle size Dec 2, 2024
@dinwwwh dinwwwh merged commit ef3ba82 into main Dec 2, 2024
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.

1 participant