Added static serve folder middleware

This commit is contained in:
sianida26 2024-05-29 19:09:00 +07:00
parent f038485cb7
commit 77fcf88d81

View File

@ -0,0 +1,15 @@
import { serveStatic } from "@hono/node-server/serve-static";
/**
* Serves static files from the specified folder, rewriting the request path.
*
* @param path - The root directory from which to serve static files.
* @returns A middleware that serves static files with the modified request path.
*/
const staticFolder = (path: string) =>
serveStatic({
root: path,
rewriteRequestPath: (path) => path.replace(/.*\//, "./"),
});
export default staticFolder;