Browse Source
Nostr-Signature: be18739cf8e9062e7163dca11c6768086cbf834d52f9758c884a420e4d9dceb7 573634b648634cbad10f2451776089ea21090d9407f715e83c577b4611ae6edc 2f068184caa9d921f38d6b132992614f39bab6ec6ea8040ac0d337db4c16de4e66de44c4d78162787f1cf8bf13978d01927b8152405f0b48adf608ca6bf34295main
3 changed files with 35 additions and 0 deletions
@ -0,0 +1,29 @@ |
|||||||
|
/** |
||||||
|
* Catch-all route to handle .md files at root level |
||||||
|
* Redirects /nostr-integration.md -> /docs/nostr-integration |
||||||
|
*
|
||||||
|
* Note: This route only handles .md files. Other routes take precedence. |
||||||
|
*/ |
||||||
|
|
||||||
|
import { redirect, error } from '@sveltejs/kit'; |
||||||
|
import type { RequestHandler } from './$types'; |
||||||
|
|
||||||
|
export const GET: RequestHandler = async ({ params }) => { |
||||||
|
const path = params.path; |
||||||
|
|
||||||
|
// Only handle .md files - return 404 for everything else
|
||||||
|
if (!path || !path.endsWith('.md')) { |
||||||
|
throw error(404, 'Not found'); |
||||||
|
} |
||||||
|
|
||||||
|
// Extract filename without .md extension
|
||||||
|
const filename = path.replace(/\.md$/, ''); |
||||||
|
|
||||||
|
// Security: Only allow alphanumeric, hyphens, underscores
|
||||||
|
if (!/^[a-zA-Z0-9_-]+$/.test(filename)) { |
||||||
|
throw error(400, 'Invalid documentation path'); |
||||||
|
} |
||||||
|
|
||||||
|
// Redirect to docs route
|
||||||
|
throw redirect(302, `/docs/${filename}`); |
||||||
|
}; |
||||||
Loading…
Reference in new issue