Skip to content

Commit 93d4cb3

Browse files
committed
feat: make api endpoint configurable
1 parent 8688a6b commit 93d4cb3

File tree

5 files changed

+14
-8
lines changed

5 files changed

+14
-8
lines changed

src/core/config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { FlytrapConfig } from './types'
22
import { empty } from './util'
33

44
export const FLYTRAP_PACKAGE_NAME = 'useflytrap'
5-
export const FLYTRAP_API_BASE = 'https://www.useflytrap.com'
5+
const FLYTRAP_API_BASE = 'https://www.useflytrap.com'
66

77
let _loadedConfig: FlytrapConfig | undefined = undefined
88

@@ -26,3 +26,4 @@ export function setFlytrapConfig(config: FlytrapConfig) {
2626
}
2727

2828
export const getLoadedConfig = () => _loadedConfig
29+
export const getApiBase = () => getLoadedConfig()?.apiBase ?? FLYTRAP_API_BASE

src/core/storage.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type {
66
DatabaseCapture,
77
Storage
88
} from './types'
9-
import { FLYTRAP_API_BASE, getLoadedConfig } from './config'
9+
import { getApiBase, getLoadedConfig } from './config'
1010
import { getUserId } from '../index'
1111
import { empty, formatBytes, get, post, tryCatchSync } from './util'
1212
import { createHumanLog } from './human-logs'
@@ -80,7 +80,7 @@ export const liveFlytrapStorage: FlytrapStorage = {
8080
loadedCaptures.set(captureId, undefined) // mark it as being loaded
8181

8282
const { data, error } = await get<DatabaseCapture>(
83-
`${FLYTRAP_API_BASE}/api/v1/captures/${captureId}`,
83+
`${getApiBase()}/api/v1/captures/${captureId}`,
8484
undefined,
8585
{
8686
headers: new Headers({
@@ -212,7 +212,7 @@ export const liveFlytrapStorage: FlytrapStorage = {
212212
}
213213

214214
const { error: captureError } = await post(
215-
`${FLYTRAP_API_BASE}/api/v1/captures`,
215+
`${getApiBase()}/api/v1/captures`,
216216
stringifiedPayload,
217217
{
218218
headers: new Headers({

src/core/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ export type FlytrapConfig = {
2323
captureId?: string
2424
mode?: FlytrapMode
2525
logging?: LogGroup[]
26+
/**
27+
* The API base address.
28+
* @default "https://www.useflytrap.com"
29+
*/
30+
apiBase?: string
2631
/**
2732
* Set this to `true` to not push artifacts
2833
* to the Flytrap API during builds. [Learn more](https://docs.useflytrap.com/config/introduction)

src/transform/artifacts/batchedArtifactsUpload.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { FLYTRAP_API_BASE } from '../../core/config'
1+
import { getApiBase } from '../../core/config'
22
import { post } from '../../core/util'
33
import { Artifact } from '../../exports'
44

@@ -48,7 +48,7 @@ export async function batchedArtifactsUpload(
4848
const uploadedArtifactBatches = await Promise.all(
4949
batches.map(async (batch) => {
5050
const { data, error } = await post<string[]>(
51-
`${FLYTRAP_API_BASE}/api/v1/artifacts/${projectId}`,
51+
`${getApiBase()}/api/v1/artifacts/${projectId}`,
5252
JSON.stringify({
5353
projectId,
5454
artifacts: batch

src/transform/artifacts/cache.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { err, formatBytes, get, ok, tryCatch } from '../../core/util'
2-
import { FLYTRAP_API_BASE } from '../../core/config'
2+
import { getApiBase } from '../../core/config'
33
import { log } from '../../core/logging'
44
import { batchedArtifactsUpload } from './batchedArtifactsUpload'
55
import { Artifact } from '../../core/types'
66

77
const getUploadedArtifacts = async (projectId: string, secretApiKey: string) => {
88
const { data, error } = await get<{ checksum: string; filePath: string }[]>(
9-
`${FLYTRAP_API_BASE}/api/v1/artifacts/${projectId}`,
9+
`${getApiBase()}/api/v1/artifacts/${projectId}`,
1010
undefined,
1111
{
1212
headers: new Headers({

0 commit comments

Comments
 (0)