From f8484b2f83911f90fc093202d8f37c80e1d86835 Mon Sep 17 00:00:00 2001 From: mat Date: Fri, 18 Mar 2022 17:38:09 -0500 Subject: Cloudflare is dumb and can't read process.env --- src/hooks.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/hooks.ts') 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) -- cgit