🔧 Create baseUrl utility.

This commit is contained in:
pheralb 2023-12-16 18:10:13 +00:00
parent 8d3590cf35
commit 0d770de827
3 changed files with 12 additions and 4 deletions

View File

@ -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,

View File

@ -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.'
});
}

7
src/utils/getBaseUrl.ts Normal file
View File

@ -0,0 +1,7 @@
export function getBaseUrl() {
if (import.meta.env.MODE === 'development') {
return '';
} else {
return import.meta.env.PUBLIC_SVGL_BASE_URL;
}
}