diff options
author | mat <github@matdoes.dev> | 2022-03-18 17:38:09 -0500 |
---|---|---|
committer | mat <github@matdoes.dev> | 2022-03-18 17:38:09 -0500 |
commit | f8484b2f83911f90fc093202d8f37c80e1d86835 (patch) | |
tree | 4e1108542086dd7c19e472a5904140f914f1e6c4 /src/hooks.ts | |
parent | f802ea11fc4d4623fad9e99ce39110c37cde619b (diff) | |
download | skyblock-stats-f8484b2f83911f90fc093202d8f37c80e1d86835.tar.gz skyblock-stats-f8484b2f83911f90fc093202d8f37c80e1d86835.tar.bz2 skyblock-stats-f8484b2f83911f90fc093202d8f37c80e1d86835.zip |
Cloudflare is dumb and can't read process.env
Diffstat (limited to 'src/hooks.ts')
-rw-r--r-- | src/hooks.ts | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/src/hooks.ts b/src/hooks.ts index 64c1b9d..6715fc3 100644 --- a/src/hooks.ts +++ b/src/hooks.ts @@ -1,8 +1,9 @@ import cookie from 'cookie' import type { ExternalFetch, GetSession, Handle } from '@sveltejs/kit' -const SKYBLOCK_STATS_API_KEY = process.env.SKYBLOCK_STATS_API_KEY -if (!SKYBLOCK_STATS_API_KEY) +// @ts-ignore Cloudflare Workers can't read process.env.SKYBLOCK_STATS_API_KEY but it can read SKYBLOCK_STATS_API_KEY +const skyblockStatsApiKey = SKYBLOCK_STATS_API_KEY || process.env.SKYBLOCK_STATS_API_KEY +if (!skyblockStatsApiKey) console.warn('SKYBLOCK_STATS_API_KEY is not set as an environment variable. This is required for logging in with Skyblock Stats to work. It should be the same as the `key` environment variable in skyblock-api.') export const handle: Handle = async ({ event, resolve }) => { @@ -22,9 +23,9 @@ export const getSession: GetSession = async ({ locals }) => { } export const externalFetch: ExternalFetch = async (request) => { - if (SKYBLOCK_STATS_API_KEY && request.url.startsWith('https://skyblock-api.matdoes.dev/')) { + if (skyblockStatsApiKey && request.url.startsWith('https://skyblock-api.matdoes.dev/')) { // add the key as a header - request.headers.set('key', SKYBLOCK_STATS_API_KEY) + request.headers.set('key', skyblockStatsApiKey) } const response = await fetch(request) |