diff --git a/__tests__/noEnvVars.test.ts b/__tests__/noEnvVars.test.ts index 132eb8e4..bb18bc5d 100644 --- a/__tests__/noEnvVars.test.ts +++ b/__tests__/noEnvVars.test.ts @@ -3,6 +3,7 @@ */ // clear Axiom env vars +process.env.AXIOM_URL = ''; process.env.AXIOM_INGEST_ENDPOINT = ''; process.env.NEXT_PUBLIC_AXIOM_INGEST_ENDPOINT = ''; import { NextWebVitalsMetric } from 'next/app'; diff --git a/__tests__/shared.test.ts b/__tests__/shared.test.ts index d3d1a975..5eca85cc 100644 --- a/__tests__/shared.test.ts +++ b/__tests__/shared.test.ts @@ -1,10 +1,22 @@ import { getIngestURL, EndpointType } from '../src/shared'; -test('reading ingest endpoint', () => { - process.env.AXIOM_INGEST_ENDPOINT = 'https://axiom.co/api/test'; +test('reading vercel ingest endpoint', () => { + process.env.AXIOM_URL = ''; + process.env.AXIOM_INGEST_ENDPOINT = 'https://axiom.co/api/v1/integrations/vercel'; let url = getIngestURL(EndpointType.webVitals); - expect(url).toEqual('https://axiom.co/api/test?type=web-vitals'); + expect(url).toEqual('https://axiom.co/api/v1/integrations/vercel?type=web-vitals'); url = getIngestURL(EndpointType.logs); - expect(url).toEqual('https://axiom.co/api/test?type=logs'); + expect(url).toEqual('https://axiom.co/api/v1/integrations/vercel?type=logs'); +}); + +test('reading axiom ingest endpoint', () => { + process.env.AXIOM_INGEST_ENDPOINT = ''; + process.env.AXIOM_URL = 'https://test.axiom.co'; + process.env.AXIOM_DATASET = 'test'; + let url = getIngestURL(EndpointType.webVitals); + expect(url).toEqual('https://test.axiom.co/api/v1/datasets/test/ingest'); + + url = getIngestURL(EndpointType.logs); + expect(url).toEqual('https://test.axiom.co/api/v1/datasets/test/ingest'); }); diff --git a/src/shared.ts b/src/shared.ts index 774e0487..91d3db29 100644 --- a/src/shared.ts +++ b/src/shared.ts @@ -1,12 +1,9 @@ export const proxyPath = '/_axiom'; const TOKEN = process.env.AXIOM_TOKEN; -const DATASET = process.env.AXIOM_DATASET; -const AXIOM_URL = process.env.AXIOM_URL; function detectEnvironmentConfiguration() { const isVercel = process.env.NEXT_PUBLIC_VERCEL_ENV ? true : false; const nodeEnv = process.env.NODE_ENV; - const datasetName = process.env.AXIOM_DATASET || null; const baseConfig = { isBrowser: typeof window !== 'undefined', @@ -15,7 +12,6 @@ function detectEnvironmentConfiguration() { isNoPrettyPrint: process.env.AXIOM_NO_PRETTY_PRINT == 'true' ? true : false, isVercel, token: TOKEN, - dataset: DATASET, }; if (isVercel) { @@ -32,7 +28,6 @@ function detectEnvironmentConfiguration() { ...baseConfig, region: '', environment: nodeEnv || 'dev', - dataset: datasetName, provider: 'self-hosted', }; } @@ -47,20 +42,18 @@ export enum EndpointType { export const getIngestURL = function (t: EndpointType) { const vercelEndpoint = process.env.NEXT_PUBLIC_AXIOM_INGEST_ENDPOINT || process.env.AXIOM_INGEST_ENDPOINT; if (vercelEndpoint) { - const ingestEndpoint = `${vercelEndpoint}/api/v1/integrations/vercel/ingest`; - const url = new URL(ingestEndpoint); + const url = new URL(vercelEndpoint); // attach type query param based on passed EndpointType url.searchParams.set('type', t.toString()); return url.toString(); } - const ingestEndpoint = `${AXIOM_URL}/api/v1/datasets/${config.dataset}/ingest`; + const ingestEndpoint = `${process.env.AXIOM_URL}/api/v1/datasets/${process.env.AXIOM_DATASET}/ingest`; if (!ingestEndpoint) { return ''; } const url = new URL(ingestEndpoint); - url.searchParams.set('type', t.toString()); return url.toString(); };