Skip to content

Commit

Permalink
Merge pull request #3 from cah4a/cors-docs
Browse files Browse the repository at this point in the history
Add info about responseMeta param
  • Loading branch information
cah4a authored May 18, 2024
2 parents 455963d + 852c4f5 commit a74fa6a
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,34 @@ Bun.serve(
// Bun serve options
port: 3001,
fetch(request, server) {
// will be fired if it's not a TRPC request
// will be executed if it's not a TRPC request
return new Response("Hello world");
},
},
),
);
```

To add response headers like Cross-origin resource sharing (CORS) use `responseMeta` option:
```ts
Bun.serve(
createBunServeHandler({
router: appRouter,
responseMeta(opts) {
return {
status: 200,
headers: {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET, POST, OPTIONS",
"Access-Control-Allow-Headers": "Content-Type, Authorization"
}
};
}
}
)
);
```

### createBunHttpHandler

Creates a Bun HTTP handler for tRPC HTTP requests:
Expand Down

0 comments on commit a74fa6a

Please sign in to comment.