diff --git a/src/routes/api/giphy/+server.ts b/src/routes/api/giphy/+server.ts index 8995c2c..3d82377 100644 --- a/src/routes/api/giphy/+server.ts +++ b/src/routes/api/giphy/+server.ts @@ -1,10 +1,13 @@ -import { GIPHY_TOKEN } from '$env/static/private'; +import { env } from '$env/dynamic/private'; import { GiphyFetch } from '@giphy/js-fetch-api'; -import { json, type RequestHandler } from '@sveltejs/kit'; - -const client = new GiphyFetch(GIPHY_TOKEN); +import { fail, json, type RequestHandler } from '@sveltejs/kit'; export const GET: RequestHandler = async ({ url }) => { + const { GIPHY_TOKEN } = env; + if (!GIPHY_TOKEN) { + throw fail(500, { message: 'could not find giphy configuration' }); + } + const client = new GiphyFetch(GIPHY_TOKEN); const query = url.searchParams.get('query'); const pageParam = url.searchParams.get('page'); const page = pageParam ? parseInt(pageParam) : 0; diff --git a/src/routes/api/unsplash/+server.ts b/src/routes/api/unsplash/+server.ts index 6b74aa6..3756a0a 100644 --- a/src/routes/api/unsplash/+server.ts +++ b/src/routes/api/unsplash/+server.ts @@ -1,9 +1,13 @@ -import { UNSPLASH_TOKEN } from '$env/static/private'; -import { json, type RequestHandler } from '@sveltejs/kit'; +import { env } from '$env/dynamic/private'; +import { fail, json, type RequestHandler } from '@sveltejs/kit'; import { createApi } from 'unsplash-js'; const client = createApi({ accessKey: UNSPLASH_TOKEN }); export const GET: RequestHandler = async ({ url }) => { + const { UNSPLASH_TOKEN } = env; + if (!UNSPLASH_TOKEN) { + throw fail(500, { message: 'could not find unsplash configuration' }); + } const query = url.searchParams.get('query'); const page = url.searchParams.has('page') ? parseInt(url.searchParams.get('page')) : 1; if (query) {