diff options
author | mat <github@matdoes.dev> | 2022-06-17 14:56:45 -0500 |
---|---|---|
committer | mat <github@matdoes.dev> | 2022-06-17 14:56:45 -0500 |
commit | a78b91ca5387fdfd1bb27b6b928154378819d9c6 (patch) | |
tree | ee74f8df7287fa4c9bb605d9b116702554e22be5 /src/lib/api.ts | |
parent | 62981dd3b864e9d4021b51ca7aaa9973c205f0bf (diff) | |
parent | 90f4b2c916cdd7f61843c7a2c7f4451d44e18367 (diff) | |
download | skyblock-stats-a78b91ca5387fdfd1bb27b6b928154378819d9c6.tar.gz skyblock-stats-a78b91ca5387fdfd1bb27b6b928154378819d9c6.tar.bz2 skyblock-stats-a78b91ca5387fdfd1bb27b6b928154378819d9c6.zip |
Merge branch 'master' into faster-heads
Diffstat (limited to 'src/lib/api.ts')
-rw-r--r-- | src/lib/api.ts | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/src/lib/api.ts b/src/lib/api.ts index e3559e1..552607c 100644 --- a/src/lib/api.ts +++ b/src/lib/api.ts @@ -1,3 +1,18 @@ +import env from './env' + // the trailing slash is required -export const API_URL = 'https://skyblock-api.matdoes.dev/' -// export const API_URL = 'http://localhost:8080/'
\ No newline at end of file +const API_URL = 'https://skyblock-api.matdoes.dev/' +// export const API_URL = 'http://localhost:8080/' + +export async function fetchApi(path: string, fetch: (info: RequestInfo, init?: RequestInit | undefined) => Promise<Response>, init?: RequestInit | undefined) { + const { SKYBLOCK_STATS_API_KEY } = env() + if (SKYBLOCK_STATS_API_KEY) { + init = init || {} + if (!init.headers) + init.headers = {} + init.headers['key'] = SKYBLOCK_STATS_API_KEY + } + + const response = await fetch(API_URL + path, init) + return response +}
\ No newline at end of file |