I need to serve some files in a directory as static files in the Svelte kit. these files are created in runtime (e.g. user uploaded files). Is there any Svelte kit built-in way to serve these files? or I should use external packages like serve-static?
these files do not exist in compile time and the src/lib/assets
or static/
directory is unsuitable.
// src/routes/media/[...path]/+server.js
export const GET = async ({ params, request }) => {
const { path } = params;
if (isFileForbiden(path)) {
throw error(404);
}
// serve static files from '__media_root__/{path}
return serve(path);
};
you have to read the file and return the buffer with
Response
.src/routes/media/[...path]/+server.js
e.g
.env