diff --git a/package.json b/package.json index 98ea2e9..70e9f90 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@handles-net/handles-server", - "version": "0.3.0", + "version": "0.3.1", "description": "Verify Bluesky handles.", "keywords": [ "bluesky", diff --git a/server.test.ts b/server.test.ts index da06cfe..48a10be 100644 --- a/server.test.ts +++ b/server.test.ts @@ -100,4 +100,22 @@ describe("Handles Server", () => { "https://example.com/domains/at.example.com?handle=not-registered.at.example.com", ); }); + + test("Replaces multiple instances of token in fallback URL", async () => { + const res = await performRequest( + { + method: "GET", + url: "/", + headers: { Host: "not-registered.at.example.com" }, + }, + { + fallbackUrl: "https://example.com/{handle}?handle={handle}", + }, + ); + + expect(res._getStatusCode()).toBe(307); + expect(res._getHeaders().location).toBe( + "https://example.com/not-registered.at.example.com?handle=not-registered.at.example.com", + ); + }) }); diff --git a/server.ts b/server.ts index 2f035c3..9089d3b 100644 --- a/server.ts +++ b/server.ts @@ -72,7 +72,7 @@ export async function handleRequest( Object.entries({ domain, handle }).forEach( ([token, value]) => - (noProfileDestination = noProfileDestination.replace( + (noProfileDestination = noProfileDestination.replaceAll( `{${token}}`, value, )), diff --git a/tsconfig.json b/tsconfig.json index 5ffca99..3df7236 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,7 +1,7 @@ { "compilerOptions": { "baseUrl": ".", - "target": "es2016", + "target": "es2021", "module": "commonjs", "outDir": "./dist", "esModuleInterop": true,