mirror of
https://github.com/pheralb/svgl.git
synced 2025-02-14 11:10:30 +08:00
⚙️ Fix get baseUrl for api.
This commit is contained in:
parent
099de90f6d
commit
e78b4e0f7f
@ -1,26 +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';
|
|
||||||
|
|
||||||
export const svgsData = svgs.map((svg: iSVG, index: number) => {
|
export const svgsData = svgs.map((svg: iSVG, index: number) => {
|
||||||
return { id: index, ...svg };
|
return { id: index, ...svg };
|
||||||
});
|
});
|
||||||
|
|
||||||
export const fullRouteSvgsData: iSVG[] = svgsData.map((svg) => {
|
|
||||||
const url = getBaseUrl();
|
|
||||||
if (typeof svg.route === 'object' && svg.route !== null) {
|
|
||||||
return {
|
|
||||||
...svg,
|
|
||||||
route: {
|
|
||||||
light: `${url}${svg.route.light}`,
|
|
||||||
dark: `${url}${svg.route.dark}`
|
|
||||||
}
|
|
||||||
};
|
|
||||||
} else if (typeof svg.route === 'string') {
|
|
||||||
return {
|
|
||||||
...svg,
|
|
||||||
route: `${url}${svg.route}`
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return svg;
|
|
||||||
});
|
|
@ -1,12 +1,33 @@
|
|||||||
import type { RequestEvent } from './$types';
|
import type { RequestEvent } from './$types';
|
||||||
|
import type { iSVG } from '@/types/svg';
|
||||||
|
|
||||||
import { error, json } from '@sveltejs/kit';
|
import { error, json } from '@sveltejs/kit';
|
||||||
|
|
||||||
// Data:
|
// Data:
|
||||||
import { fullRouteSvgsData } from '@/data';
|
import { svgsData } from '@/data';
|
||||||
|
|
||||||
export const GET = ({ url }: RequestEvent) => {
|
export const GET = ({ url }: RequestEvent) => {
|
||||||
const getParams = url.searchParams.get('limit');
|
const getParams = url.searchParams.get('limit');
|
||||||
|
const fullUrl = url.origin ?? 'svgl.vercel.app';
|
||||||
|
|
||||||
|
// Add full route to svgs:
|
||||||
|
const fullRouteSvgsData: iSVG[] = svgsData.map((svg) => {
|
||||||
|
if (typeof svg.route === 'object' && svg.route !== null) {
|
||||||
|
return {
|
||||||
|
...svg,
|
||||||
|
route: {
|
||||||
|
light: `${fullUrl}${svg.route.light}`,
|
||||||
|
dark: `${fullUrl}${svg.route.dark}`
|
||||||
|
}
|
||||||
|
};
|
||||||
|
} else if (typeof svg.route === 'string') {
|
||||||
|
return {
|
||||||
|
...svg,
|
||||||
|
route: `${fullUrl}${svg.route}`
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return svg;
|
||||||
|
});
|
||||||
|
|
||||||
// Status 200 | If no limit is provided, return all svgs:
|
// Status 200 | If no limit is provided, return all svgs:
|
||||||
if (!getParams) {
|
if (!getParams) {
|
||||||
|
@ -1,7 +0,0 @@
|
|||||||
export function getBaseUrl() {
|
|
||||||
if (import.meta.env.MODE === 'development') {
|
|
||||||
return '';
|
|
||||||
} else {
|
|
||||||
return import.meta.env.PUBLIC_SVGL_BASE_URL;
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user