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