aboutsummaryrefslogtreecommitdiff
path: root/src/hooks.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/hooks.ts')
-rw-r--r--src/hooks.ts9
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)