Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions apps/telemetry-worker/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,25 @@ describe('telemetry ingest', () => {
expect(points[2].blobs).toEqual(['yes']);
});

it('rejects GET with 405', async () => {
const { env } = makeEnv();
it('redirects GET to the telemetry docs with 302 without writing points', async () => {
const { env, points } = makeEnv();
const res = await worker.fetch(
new Request('https://telemetry.pgflow.dev/', { method: 'GET' }),
env,
);
expect(res.status).toBe(302);
expect(res.headers.get('location')).toBe('https://pgflow.dev/reference/telemetry/');
expect(points).toHaveLength(0);
});

it.each(['HEAD', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'])('rejects %s with 405 without writing points', async (method) => {
const { env, points } = makeEnv();
const res = await worker.fetch(
new Request('https://telemetry.pgflow.dev/', { method }),
env,
);
expect(res.status).toBe(405);
expect(points).toHaveLength(0);
});

it('rejects malformed JSON with 400', async () => {
Expand Down
3 changes: 3 additions & 0 deletions apps/telemetry-worker/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ const reject = (status: number) => new Response(null, {

export default {
async fetch(request: Request, env: Env): Promise<Response> {
if (request.method === 'GET') {
return Response.redirect('https://pgflow.dev/reference/telemetry/', 302);
}
if (request.method !== 'POST') return reject(405);

const contentType = request.headers.get('content-type') ?? '';
Expand Down
4 changes: 4 additions & 0 deletions apps/telemetry-worker/wrangler.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ name = "pgflow-telemetry"
main = "src/index.ts"
compatibility_date = "2026-09-01"

[[routes]]
pattern = "telemetry.pgflow.dev"
custom_domain = true

[[analytics_engine_datasets]]
binding = "PGFLOW_TELEMETRY"
dataset = "pgflow_telemetry"
Expand Down
Loading