fix: catch all the path

This commit is contained in:
KazooTTT
2024-11-23 22:20:58 +08:00
parent 693b063489
commit 7838cdee1a

View File

@ -1,7 +1,10 @@
import type { APIRoute } from 'astro'; import type { APIRoute } from 'astro';
export const GET: APIRoute = async ({ params, locals, request }) => { export const GET: APIRoute = async ({ params, locals, request }) => {
const slug = params.slug; // Handle multiple path segments and decode the URL-encoded slug
const slugSegments = params.slug?.split('/') || [];
const slug = decodeURIComponent(slugSegments.join('/'));
if (!slug) { if (!slug) {
return new Response(JSON.stringify({ error: 'Slug is required' }), { return new Response(JSON.stringify({ error: 'Slug is required' }), {
status: 400, status: 400,
@ -69,7 +72,10 @@ export const GET: APIRoute = async ({ params, locals, request }) => {
}; };
export const POST: APIRoute = async ({ params, locals, request }) => { export const POST: APIRoute = async ({ params, locals, request }) => {
const slug = params.slug; // Handle multiple path segments and decode the URL-encoded slug
const slugSegments = params.slug?.split('/') || [];
const slug = decodeURIComponent(slugSegments.join('/'));
if (!slug) { if (!slug) {
return new Response(JSON.stringify({ error: 'Slug is required' }), { return new Response(JSON.stringify({ error: 'Slug is required' }), {
status: 400, status: 400,