OpenPanel is an open-source web and product analytics platform, an open-source alternative to Mixpanel with optional self-hosting.
tools: restore the /tools prefix both public endpoints lost
Carl-Gerhard Lindesvärdb42f582b5be5
diff --git a/packages/core/src/modules/tools/tools.routes.test.ts b/packages/core/src/modules/tools/tools.routes.test.tsnew file mode 100644index 000000000..3ed9229a5--- /dev/null+++ b/packages/core/src/modules/tools/tools.routes.test.ts@@ -0,0 +1,26 @@+// The `/tools` prefix came from `instance.register(toolsRouter, { prefix:+// '/tools' })` in V1's app.ts, over a router whose own urls were bare.+// `defineRoutes` has no prefix mechanism, so the port dropped the segment and+// both routes answered at the root — apps/public's own pages call+// `${API_URL}/tools/ip-lookup` and were 404ing. Nothing covered the path,+// which is why it slipped.++import { describe, expect, test } from 'bun:test';+import { readFileSync } from 'node:fs';++const SOURCE = readFileSync(+ new URL('./tools.routes.ts', import.meta.url),+ 'utf8'+);++describe("tools routes keep V1's public paths", () => {+ test('both routes are registered under /tools', () => {+ expect(SOURCE).toContain("'/tools/site-checker'");+ expect(SOURCE).toContain("'/tools/ip-lookup'");+ });++ test('neither is registered at the root', () => {+ expect(SOURCE).not.toContain(" '/site-checker',");+ expect(SOURCE).not.toContain(" '/ip-lookup',");+ });+});diff --git a/packages/core/src/modules/tools/tools.routes.ts b/packages/core/src/modules/tools/tools.routes.tsindex ee5f4ecfb..46ba9680f 100644--- a/packages/core/src/modules/tools/tools.routes.ts+++ b/packages/core/src/modules/tools/tools.routes.ts@@ -4,6 +4,13 @@// into publicApiRoutes since M9-004; both routes stay unauthenticated (V1's// shape) and hidden from the OpenAPI document, matching V1's// `schema: { hide: true }`.+//+// The `/tools` prefix is spelled out here. V1 got it from+// `instance.register(toolsRouter, { prefix: '/tools' })` (app.ts:386) over a+// router whose own urls were bare, and `defineRoutes` has no prefix+// mechanism — so the port dropped the segment and both routes answered at the+// root. apps/public's own pages call `${API_URL}/tools/ip-lookup` and+// `/tools/site-checker`, so they were 404ing.import { z } from 'zod';import { defineRoutes } from '../../http/define';@@ -15,7 +22,7 @@ const TAGS = ['Tools'];export const toolsRoutes = defineRoutes((app) =>app.get(- '/site-checker',+ '/tools/site-checker',async ({ query, ctx, status }) => {const outcome = await runSiteCheck(ctx.config,@@ -34,7 +41,7 @@ export const toolsRoutes = defineRoutes((app) =>}).get(- '/ip-lookup',+ '/tools/ip-lookup',async ({ query, ctx, status }) => {const outcome = await runIpLookup(ctx.config,