Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/content/content/docs/client/react-query.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { ORPCLink } from '@orpc/client/fetch';
import type { router } from 'examples/server';

const orpcLink = new ORPCLink({
url: 'http://localhost:3000/api',
url: 'http://localhost:3000/rpc',
// fetch: optional override for the default fetch function
// headers: provide additional headers
})
Expand Down
6 changes: 3 additions & 3 deletions apps/content/content/docs/client/vanilla.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { ORPCLink } from '@orpc/client/fetch'
import type { router } from 'examples/server'

const orpcLink = new ORPCLink({
url: 'http://localhost:3000/api',
url: 'http://localhost:3000/rpc',
// fetch: optional override for the default fetch function
// headers: provide additional headers
})
Expand Down Expand Up @@ -51,7 +51,7 @@ type ClientContext = { cache?: RequestCache } | undefined
// if context is not undefinable, it will require you pass context in every call

const orpcLink = new ORPCLink<ClientContext>({
url: 'http://localhost:3000/api',
url: 'http://localhost:3000/rpc',
// headers: provide additional headers
fetch: (input, init, context) => globalThis.fetch(input, {
...init,
Expand Down Expand Up @@ -90,7 +90,7 @@ import { createORPCClient, DynamicLink, ORPCError } from '@orpc/client'
import { ORPCLink } from '@orpc/client/fetch'

const orpcLink1 = new ORPCLink({
url: 'http://localhost:3000/api',
url: 'http://localhost:3000/rpc',
// headers: provide additional headers
})

Expand Down
2 changes: 1 addition & 1 deletion apps/content/content/docs/client/vue-colada.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { ORPCLink } from '@orpc/client/fetch';
import type { router } from 'examples/server';

const orpcLink = new ORPCLink({
url: 'http://localhost:3000/api',
url: 'http://localhost:3000/rpc',
// fetch: optional override for the default fetch function
// headers: provide additional headers
});
Expand Down
2 changes: 1 addition & 1 deletion apps/content/content/docs/client/vue-query.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { ORPCLink } from '@orpc/client/fetch';
import type { router } from 'examples/server';

const orpcLink = new ORPCLink({
url: 'http://localhost:3000/api',
url: 'http://localhost:3000/rpc',
// fetch: optional override for the default fetch function
// headers: provide additional headers
});
Expand Down
2 changes: 1 addition & 1 deletion apps/content/content/docs/contract-first.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ import { ORPCLink } from '@orpc/client/fetch'
import type { contract } from 'examples/contract'

const orpcLink = new ORPCLink({
url: 'https://localhost:3000/prefix',
url: 'https://localhost:3000/rpc',
// fetch: optional override for the default fetch function
// headers: provide additional headers
})
Expand Down
23 changes: 19 additions & 4 deletions apps/content/content/docs/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ In oRPC middleware is very useful and fully typed you can find more info [here](
## Start Your Server

```ts twoslash
import { ORPCHandler, CompositeHandler } from '@orpc/server/node'
import { ORPCHandler } from '@orpc/server/node'
import { OpenAPIServerlessHandler } from '@orpc/openapi/node'
import { createServer } from 'node:http'
import { router } from 'examples/server'
Expand All @@ -157,15 +157,30 @@ const openapiHandler = new OpenAPIServerlessHandler(router, {
new ZodCoercer(),
],
})

const orpcHandler = new ORPCHandler(router)
const compositeHandler = new CompositeHandler([openapiHandler, orpcHandler])

const server = createServer(async (req, res) => {
if (req.url?.startsWith('/api')) {
return compositeHandler.handle(req, res, {
const { matched } = await openapiHandler.handle(req, res, {
prefix: '/api',
context: {},
})

if(matched){
return
}
}

if(req.url?.startsWith('/rpc')){
const { matched } = await orpcHandler.handle(req, res, {
prefix: '/rpc',
context: {},
})

if(matched){
return
}
}

res.statusCode = 404
Expand All @@ -190,7 +205,7 @@ import { ORPCLink } from '@orpc/client/fetch'
import type { router } from 'examples/server'

const orpcLink = new ORPCLink({
url: 'http://localhost:3000/api',
url: 'http://localhost:3000/rpc',
// fetch: optional override for the default fetch function
// headers: provide additional headers
})
Expand Down
12 changes: 8 additions & 4 deletions apps/content/content/docs/server/context.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,11 @@ import { OpenAPIServerlessHandler, OpenAPIServerHandler } from '@orpc/openapi/fe

const orpcHandler = new ORPCHandler(router)

export function fetch(request: Request) {
export async function fetch(request: Request) {
// No need to pass context; middleware handles it
return orpcHandler.fetch(request)
const { response } = await orpcHandler.handle(request)

return response ?? new Response('Not found', { status: 404 })
}
```

Expand Down Expand Up @@ -130,12 +132,14 @@ export const router = base.router({

const orpcHandler = new ORPCHandler(router)

export function fetch(request: Request) {
export async function fetch(request: Request) {
// Initialize context explicitly for each request
const db = 'fake-db' as const
const user = request.headers.get('Authorization') ? { id: 'example' } : undefined

return orpcHandler.fetch(request, { context: { db, user } })
const { response } = await orpcHandler.handle(request, { context: { db, user } })

return response ?? new Response('Not Found', { status: 404 })
}

// If you want to call this procedure or use as server action
Expand Down
2 changes: 1 addition & 1 deletion apps/content/content/docs/server/file-upload.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ import { createORPCClient } from '@orpc/client'
import { ORPCLink } from '@orpc/client/fetch'

const orpcLink = new ORPCLink({
url: 'http://localhost:3000/api',
url: 'http://localhost:3000/rpc',
// fetch: optional override for the default fetch function
// headers: provide additional headers
})
Expand Down
Loading