From 05556e6cda22fb736e0e32090bf1f216406cc301 Mon Sep 17 00:00:00 2001 From: "Michael J. Roberts" Date: Thu, 8 Jun 2023 21:59:18 +0100 Subject: [PATCH] refactor: Amend to setHeader & setResponseStatus h3 methods in defineNitroEventHandler. refactor: Amend to setHeader & setResponseStatus h3 methods in defineNitroEventHandler. --- src/defineNitroTRPCEventHandler.ts | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/defineNitroTRPCEventHandler.ts b/src/defineNitroTRPCEventHandler.ts index 6f6db0c..47c680d 100644 --- a/src/defineNitroTRPCEventHandler.ts +++ b/src/defineNitroTRPCEventHandler.ts @@ -20,7 +20,15 @@ import { type HTTPRequest, type ResponseMeta, resolveHTTPResponse } from '@trpc/ import { createURL } from 'ufo' -import { type EventHandler, type H3Event, defineEventHandler, readBody, isMethod } from 'h3' +import { + type EventHandler, + type H3Event, + defineEventHandler, + readBody, + setHeader, + isMethod, + setResponseStatus +} from 'h3' /*****************************************************************************************************************/ @@ -92,7 +100,7 @@ export const defineNitroTRPCEventHandler: NitroRequestHandler = { return defineEventHandler(async event => { // Extract the request and response objects from the H3 event: - const { req: request, res: response } = event.node + const { req: request } = event.node // Create a URL object from the request URL: const url = createURL(request.url!) @@ -127,12 +135,14 @@ export const defineNitroTRPCEventHandler: NitroRequestHandler = { - response.setHeader(key, headers[key]!) + if (headers[key]) { + setHeader(event, key, headers[key]!) + } }) // Return the response body "as is", JSON "stringified":