1// A host without Cloudflare's edge (docs/16-hosting-without-cloudflare.md):2// a proxy can ask which hostnames are ours before it fetches certificates3// for them. The address and lease pieces are test/unit/edge.test.ts.4import { SELF, env } from "cloudflare:test";5import { describe, it, expect } from "vitest";6import { hostnameKnown } from "../../src/edge.ts";78describe("which hostnames are ours", () => {9 it("knows the apex, valid and reserved names under it and mapped custom hostnames, and nothing else", async () => {10 const e = { DOMAIN: "bind.ws", HOSTS: env.HOSTS };11 await env.HOSTS.put("relay.example.org", "kitchen");12 expect(await hostnameKnown(e, "bind.ws")).toBe(true);13 expect(await hostnameKnown(e, "www.bind.ws")).toBe(true);14 expect(await hostnameKnown(e, "Kitchen.bind.ws.")).toBe(true);15 expect(await hostnameKnown(e, "api.bind.ws")).toBe(true);16 expect(await hostnameKnown(e, "relay.example.org")).toBe(true);17 expect(await hostnameKnown(e, "a.b.bind.ws")).toBe(false);18 expect(await hostnameKnown(e, "-bad.bind.ws")).toBe(false);19 expect(await hostnameKnown(e, "other.example.org")).toBe(false);20 expect(await hostnameKnown(e, "")).toBe(false);21 });2223 it("answers a proxy's question on any host with a status and no body", async () => {24 const ask = async (domain: string) => (await SELF.fetch(`http://bind.ws/.well-known/bindws/hostname?domain=${encodeURIComponent(domain)}`)).status;25 expect(await ask("kitchen.bind.ws")).toBe(200);26 expect(await ask("bind.ws")).toBe(200);27 expect(await ask("nope.example.org")).toBe(404);28 const r = await SELF.fetch("http://anything.example/.well-known/bindws/hostname?domain=kitchen.bind.ws");29 expect([r.status, await r.text()]).toEqual([200, ""]);30 });31});