Skip to content

Commit 60e7a27

Browse files
committed
feat: add redirect
1 parent 6f2aede commit 60e7a27

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

lib/handlers/redirect.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { expect, test } from "vitest";
2+
import { redirect } from "./redirect";
3+
4+
test("redirect", () => {
5+
const res = redirect("/foo");
6+
expect(res.status).toMatchInlineSnapshot(`302`);
7+
expect(res.headers.get("location")).toMatchInlineSnapshot(`"/foo"`);
8+
});

lib/handlers/redirect.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function redirect(path: string): Response {
2+
return new Response(null, { status: 302, headers: { Location: path } });
3+
}

0 commit comments

Comments
 (0)