From 25e926ae82984788048cf512706cddd479da7578 Mon Sep 17 00:00:00 2001 From: MARCROCK22 <57925328+MARCROCK22@users.noreply.github.com> Date: Wed, 8 May 2024 19:56:05 -0400 Subject: [PATCH] fix: cf workers support --- src/client/httpclient.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/client/httpclient.ts b/src/client/httpclient.ts index 8e0c8ce..33119c1 100644 --- a/src/client/httpclient.ts +++ b/src/client/httpclient.ts @@ -8,7 +8,7 @@ import { filetypeinfo } from 'magic-bytes.js'; import type { HttpRequest, HttpResponse } from 'uWebSockets.js'; import { OverwrittenMimeTypes } from '../api'; import { isBufferLike } from '../api/utils/utils'; -import type { DeepPartial } from '../common'; +import { isCloudfareWorker, type DeepPartial } from '../common'; import type { BaseClientOptions, InternalRuntimeConfigHTTP, StartOptions } from './base'; import { BaseClient } from './base'; import { onInteractionCreate } from './oninteractioncreate'; @@ -160,7 +160,11 @@ export class HttpClient extends BaseClient { ); default: return new Promise(r => { - onInteractionCreate(this, rawBody, -1, async ({ body, files }) => { + if (isCloudfareWorker()) + return onInteractionCreate(this, rawBody, -1) + .then(() => r(new Response())) + .catch(() => r(new Response())); + return onInteractionCreate(this, rawBody, -1, async ({ body, files }) => { let response: FormData | APIInteractionResponse; const headers: { 'Content-Type'?: string } = {};