Table of Contents
Sveltekit Files endpoint
How to list files with sveltekit
src/routes/api/files/+server.ts
import { json } from '@sveltejs/kit';
export const GET = () => {
const files = import.meta.glob('../../../static/*');
return json({
images: Object.keys(files).map((key) => key.split('/').pop())
});
};
// returns {"images":["file1.png","file2.png"]}
Related snippets
Add Darkmode to sveltekit
How to add darkmode to a sveltekit project
Create images from HTML
How to convert html to an image on the server as a sveltekit API endpoint
Discord oAuth with Sveltekit
How to log in to a website with discord
How to use MSW with SvelteKit
Mock API requests in development with Mock Service Worker