🐛 Import plugins directly into svgr

This commit is contained in:
pheralb
2024-04-09 23:26:51 +01:00
parent f1db803782
commit 6000cbb6a5
2 changed files with 36 additions and 7 deletions
+21 -1
View File
@@ -3,7 +3,27 @@ import type { RequestEvent } from '../$types';
import { transform } from '@svgr/core';
import { json } from '@sveltejs/kit';
import { ratelimit } from '@/server/redis';
// SVGR Plugins:
import svgrJSX from '@svgr/plugin-jsx';
export const POST = async ({ request }: RequestEvent) => {
const ip = request.headers.get('x-forwarded-for') ?? '';
const { success, reset } = await ratelimit.limit(ip);
// Error 429 | If rate limit is exceeded:
if (!success) {
const now = Date.now();
const retryAfter = Math.floor((reset - now) / 500);
return new Response('Too Many Requests', {
status: 429,
headers: {
'Retry-After': retryAfter.toString()
}
});
}
try {
const body = await request.json();
@@ -14,7 +34,7 @@ export const POST = async ({ request }: RequestEvent) => {
const jsCode = await transform(
svgCode,
{
plugins: ['@svgr/plugin-jsx'],
plugins: [svgrJSX],
icon: true,
typescript: typescript
},