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
7 changes: 7 additions & 0 deletions .changeset/polite-islands-try.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@rocket.chat/meteor": patch
---

Fixes buffer as response from API

Currently, the only known case affected is Apps Engine icons. This patch ensures the API returns a buffer as the response, resolving issues with clients expecting a binary payload.
7 changes: 5 additions & 2 deletions apps/meteor/app/api/server/definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,15 +206,18 @@ type ActionThis<TMethod extends Method, TPathPattern extends PathPattern, TOptio
readonly token?: string;
});

export type ResultFor<TMethod extends Method, TPathPattern extends PathPattern> =
export type ResultFor<TMethod extends Method, TPathPattern extends PathPattern> = (
| SuccessResult<OperationResult<TMethod, TPathPattern>>
| FailureResult<unknown, unknown, unknown, unknown>
| UnauthorizedResult<unknown>
| NotFoundResult
| {
statusCode: number;
body: unknown;
};
}
) & {
headers?: Record<string, string>;
};

export type Action<TMethod extends Method, TPathPattern extends PathPattern, TOptions> =
| ((this: ActionThis<TMethod, TPathPattern, TOptions>) => Promise<ResultFor<TMethod, TPathPattern>>)
Expand Down
11 changes: 11 additions & 0 deletions apps/meteor/app/api/server/middlewares/honoAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@ export const honoAdapter = (hono: Hono) => async (expressReq: Request, res: Resp
);
res.status(honoRes.status);
honoRes.headers.forEach((value, key) => res.setHeader(key, value));

if (!honoRes.body) {
res.end();
return;
}

if (honoRes.body instanceof ReadableStream) {
Readable.fromWeb(honoRes.body as any).pipe(res);
return;
}

// Converting it to a Buffer because res.send appends always a charset to the Content-Type
// https://github.com/expressjs/express/issues/2238
res.send(Buffer.from(await honoRes.text()));
Expand Down
Loading
Loading