Skip to content

Commit

Permalink
fix response check
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Jul 10, 2023
1 parent ec5ab9f commit ea0daa0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@ import {
H3Event,
} from "./event";
import { createError } from "./error";
import { send, sendStream, isStream, MIMES, sendWebResponse } from "./utils";
import {
send,
sendStream,
isStream,
MIMES,
sendWebResponse,
isWebResponse,
} from "./utils";
import type { EventHandler, LazyEventHandler } from "./types";

export interface Layer {
Expand Down Expand Up @@ -126,7 +133,7 @@ export function createAppEventHandler(stack: Stack, options: AppOptions) {

if (val) {
// Web Response
if (typeof Response !== undefined && val instanceof Response) {
if (isWebResponse(val)) {
return sendWebResponse(event, val);
}

Expand Down
4 changes: 4 additions & 0 deletions src/utils/response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ export function isStream(data: any): data is Readable | ReadableStream {
return false;
}

export function isWebResponse(data: any): data is Response {
return typeof Response !== "undefined" && data instanceof Response;
}

export function sendStream(
event: H3Event,
stream: Readable | ReadableStream
Expand Down

0 comments on commit ea0daa0

Please sign in to comment.