testServerFunctionsKnowTheirLocalAddress

tcmts.atproto.test.testServerFunctionsKnowTheirLocalAddress · #um7ukxxc · function

With no service URL set, a server function (asked with only a path) is the localhost address the browser asked, or the one a proxy names; anywhere else, nothing.

import { serviceAudiences } from "#codebase/tcmts/atproto";
import { withRequest } from "#codebase/tcmts/atproto/lib/server";
import assert from "node:assert/strict";

export const testServerFunctionsKnowTheirLocalAddress = async () => {
  const at = async (headers: Record<string, string>) =>
    (await withRequest({ url: "/_tcm/rpc/x", headers }, () => serviceAudiences())).value;
  assert.deepEqual(await at({ host: "127.0.0.1:5173" }), ["did:web:localhost%3A5173"]);
  assert.deepEqual(await at({ host: "[::1]:9000", "x-forwarded-host": "localhost:5173" }), [
    "did:web:localhost%3A5173",
  ]);
  assert.deepEqual(await at({ host: "app.example" }), []);
}

uses