mirror of
https://github.com/pheralb/svgl.git
synced 2024-11-10 14:46:54 +08:00
🔧 Create baseUrl utility.
This commit is contained in:
parent
8d3590cf35
commit
0d770de827
@ -1,5 +1,6 @@
|
|||||||
import type { iSVG } from '@/types/svg';
|
import type { iSVG } from '@/types/svg';
|
||||||
import { svgs } from './svgs';
|
import { svgs } from './svgs';
|
||||||
|
import { getBaseUrl } from '@/utils/getBaseUrl';
|
||||||
|
|
||||||
// Add id on top of each svg:
|
// Add id on top of each svg:
|
||||||
export const svgsData = svgs.map((svg: iSVG, index: number) => {
|
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:
|
// Add full route of each svg, checking if theme support is added:
|
||||||
export const fullRouteSvgsData: iSVG[] = svgsData.map((svg) => {
|
export const fullRouteSvgsData: iSVG[] = svgsData.map((svg) => {
|
||||||
const url = 'https://svgl.vercel.app';
|
const url = getBaseUrl();
|
||||||
if (typeof svg.route === 'object' && svg.route !== null) {
|
if (typeof svg.route === 'object' && svg.route !== null) {
|
||||||
return {
|
return {
|
||||||
...svg,
|
...svg,
|
||||||
|
@ -17,21 +17,21 @@ export const GET = ({ url }: RequestEvent) => {
|
|||||||
|
|
||||||
// Error 400 | if limit is not a number:
|
// Error 400 | if limit is not a number:
|
||||||
if (isNaN(limit)) {
|
if (isNaN(limit)) {
|
||||||
throw error(400, {
|
error(400, {
|
||||||
message: 'Limit must be a number.'
|
message: 'Limit must be a number.'
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Error 400 | If limit is not positive:
|
// Error 400 | If limit is not positive:
|
||||||
if (limit < 1) {
|
if (limit < 1) {
|
||||||
throw error(400, {
|
error(400, {
|
||||||
message: 'Limit must be a positive number.'
|
message: 'Limit must be a positive number.'
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Error 400 | If limit is greater than the number of svgs:
|
// Error 400 | If limit is greater than the number of svgs:
|
||||||
if (limit > fullRouteSvgsData.length) {
|
if (limit > fullRouteSvgsData.length) {
|
||||||
throw error(400, {
|
error(400, {
|
||||||
message: 'Limit is greater than the number of svgs.'
|
message: 'Limit is greater than the number of svgs.'
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
7
src/utils/getBaseUrl.ts
Normal file
7
src/utils/getBaseUrl.ts
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
export function getBaseUrl() {
|
||||||
|
if (import.meta.env.MODE === 'development') {
|
||||||
|
return '';
|
||||||
|
} else {
|
||||||
|
return import.meta.env.PUBLIC_SVGL_BASE_URL;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user