Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Vercjames/package-trpc-swagger
Browse files Browse the repository at this point in the history
  • Loading branch information
Vercjames committed Dec 13, 2024
2 parents 68e1f7d + a24d405 commit a93c151
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "trpc-swagger",
"license": "MIT",
"version": "1.2.6",
"version": "1.2.7",
"description": "tRPC Swagger Wrapper",
"author": "https://github.com/vercjames",
"homepage": "https://github.com/vercjames/package-trpc-swagger",
Expand Down
14 changes: 13 additions & 1 deletion packages/adapters/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ import { CreateOpenApiNodeHttpHandlerOptions, createOpenApiNodeHttpHandler } fro
// =================================================================================================
export type CreateOpenApiFetchHandlerOptions<TRouter extends OpenApiRouter> = Omit<FetchHandlerOptions<TRouter>, "batching"> & {
req: Request;
endpoint: `/${string}`;
endpoint: `/${string}`
cors?: {
origin: string
methods?: string[]
headers?: string[]
}
};

// Application Sectional || Define Helper Functions
Expand Down Expand Up @@ -106,6 +111,13 @@ export const createOpenApiFetchHandler = async <TRouter extends OpenApiRouter>(
const url = new URL(opts.req.url.replace(opts.endpoint, ""))
const req: Request = await createRequestProxy(opts.req, url.toString())

if (opts.cors) {
const { origin, methods, headers } = opts.cors
resHeaders.set("Access-Control-Allow-Origin", origin)
if (methods) resHeaders.set("Access-Control-Allow-Methods", methods.join(", "))
if (headers) resHeaders.set("Access-Control-Allow-Headers", headers.join(", "))
}

const createContext = () => {
if (opts.createContext) {
return opts.createContext({ req: opts.req, resHeaders })
Expand Down

0 comments on commit a93c151

Please sign in to comment.