Skip to content

Commit

Permalink
add redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
ragokan committed Sep 18, 2024
1 parent 937ce35 commit 861c7d7
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/server/src/context/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,14 @@ export class BunicornContext<
return Response.json(body, init) as BunicornResponse<T>;
}

public redirect(url: string, status = 302) {
this.headers.set("Location", url);
return new Response(undefined, {
status,
headers: this.headers,
}) as BunicornResponse<never>;
}

// TODO: Move this to a separate handler
public stream<T>(body: ReadableStream<T>, init: BuniResponseInit = {}) {
this.headers.set("Content-Type", "text/event-stream");
Expand Down

0 comments on commit 861c7d7

Please sign in to comment.