Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

http.test.ts

28 lines1.0 KB

1import { expect, it } from "@effect/vitest";
2import { describe } from "vite-plus/test";
3​
4import { isLoopbackHostname, resolveDevRedirectUrl } from "./http.ts";
5​
6describe("http dev routing", () => {
7 it("treats localhost and loopback addresses as local", () => {
8 expect(isLoopbackHostname("127.0.0.1")).toBe(true);
9 expect(isLoopbackHostname("localhost")).toBe(true);
10 expect(isLoopbackHostname("::1")).toBe(true);
11 expect(isLoopbackHostname("[::1]")).toBe(true);
12 });
13​
14 it("does not treat LAN addresses as local", () => {
15 expect(isLoopbackHostname("192.168.86.35")).toBe(false);
16 expect(isLoopbackHostname("10.0.0.24")).toBe(false);
17 expect(isLoopbackHostname("example.local")).toBe(false);
18 });
19​
20 it("preserves path and query when redirecting to the dev server", () => {
21 const devUrl = new URL("http://127.0.0.1:5173/");
22 const requestUrl = new URL("http://127.0.0.1:3774/pair?token=test-token");
23​
24 expect(resolveDevRedirectUrl(devUrl, requestUrl)).toBe(
25 "http://127.0.0.1:5173/pair?token=test-token",
26 );
27 });
28});