diff --git a/src/data/index.ts b/src/data/index.ts index e18741f..32d65bc 100644 --- a/src/data/index.ts +++ b/src/data/index.ts @@ -1,5 +1,6 @@ import type { iSVG } from '@/types/svg'; import { svgs } from './svgs'; +import { getBaseUrl } from '@/utils/getBaseUrl'; // Add id on top of each svg: export const svgsData = svgs.map((svg: iSVG, index: number) => { @@ -8,7 +9,7 @@ export const svgsData = svgs.map((svg: iSVG, index: number) => { // Add full route of each svg, checking if theme support is added: export const fullRouteSvgsData: iSVG[] = svgsData.map((svg) => { - const url = 'https://svgl.vercel.app'; + const url = getBaseUrl(); if (typeof svg.route === 'object' && svg.route !== null) { return { ...svg, diff --git a/src/routes/api/svgs/+server.ts b/src/routes/api/svgs/+server.ts index eb02825..ebea0be 100644 --- a/src/routes/api/svgs/+server.ts +++ b/src/routes/api/svgs/+server.ts @@ -17,21 +17,21 @@ export const GET = ({ url }: RequestEvent) => { // Error 400 | if limit is not a number: if (isNaN(limit)) { - throw error(400, { + error(400, { message: 'Limit must be a number.' }); } // Error 400 | If limit is not positive: if (limit < 1) { - throw error(400, { + error(400, { message: 'Limit must be a positive number.' }); } // Error 400 | If limit is greater than the number of svgs: if (limit > fullRouteSvgsData.length) { - throw error(400, { + error(400, { message: 'Limit is greater than the number of svgs.' }); } diff --git a/src/utils/getBaseUrl.ts b/src/utils/getBaseUrl.ts new file mode 100644 index 0000000..ee8759a --- /dev/null +++ b/src/utils/getBaseUrl.ts @@ -0,0 +1,7 @@ +export function getBaseUrl() { + if (import.meta.env.MODE === 'development') { + return ''; + } else { + return import.meta.env.PUBLIC_SVGL_BASE_URL; + } +}