-
1️⃣ Imports required for proper operation
import { Hono } from "jsr:@hono/hono@4.7.8"; import { serveStatic } from "jsr:@hono/hono@4.7.8/deno"; import type { MiddlewareHandler } from "jsr:@hono/hono@4.7.8"; import { walk } from "jsr:@std/fs@1.0.17/walk";
-
2️⃣ And import this module
-
2️⃣✳️1️⃣ Directly from jsr repository
import { type HonoFtpOptions, honoDenoFtp } from "jsr:@cis/hono-ftp@0.2.6";
-
2️⃣✳️2️⃣ Directly from github repository
import { type HonoFtpOptions, honoDenoFtp } from "https://raw.githubusercontent.com/mod-by-cis/hono-deno-ftp/refs/tags/v0.2.6/mod.ts";
-
2️⃣✳️3️⃣ indirectly from deno.json
Add Package
deno add jsr:@cis/hono-ftp
Import symbol
import { type HonoFtpOptions, honoDenoFtp } from "@cis/hono-ftp";
-
2️⃣✳️4️⃣ indirectly from re-exports eg. deps.ts
import { type HonoFtpOptions, honoDenoFtp } from "../deps.ts";
-
-
🅰️ minimal configurationconst appMain = new Hono(); appMain.use( honoDenoFtp< MiddlewareHandler, typeof serveStatic, typeof walk >({ dir: "./path/to/your/rootOfFiles/folder", url: "/f", deps: [serveStatic, walk], // layout: (urlPath, entries) => customHtml } as HonoFtpOptions< MiddlewareHandler, typeof serveStatic, typeof walk >) ); appMain.get('/', (c) => { return c.text('Hello Hono!'); }); Deno.serve(/*{port:8007},*/ appMain.fetch);
-
🅱️ optionally you can overwrite the layout of our FTPconst appMain = new Hono(); appMain.use( honoDenoFtp< MiddlewareHandler, typeof serveStatic, typeof walk >({ dir: "./path/to/your/rootOfFiles/folder", url: "/f", deps: [serveStatic, walk], layout: (urlPath, entries) => { console.log("#############", entries); const parentPath = urlPath.replace(/\/+$/, "").split("/").slice(0, -1).join("/") || "/"; return ` <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <title>Katalog ${urlPath}</title> <style> body { font-family: sans-serif; padding: 2rem; background: #f0f0f0; } ul { list-style-type: none; padding: 0; } li { margin: 0.3rem 0; } a { color: #007bff; text-decoration: none; } a:hover { text-decoration: underline; } .nav { margin-bottom: 1rem; } </style> </head> <body> <h2>📁 Index of ${urlPath}</h2> <div class="nav"> ${urlPath !== "/" ? `<a href="${parentPath}/">↩️ W górę</a>` : ""} </div> <ul> ${entries.map(e => `<li><a href="${urlPath}${e}">${e}</a></li>`).join("")} </ul> <hr /> <footer><small>Hono-FTP + przycisk "W górę" 🦕</small></footer> </body> </html> `; } } as HonoFtpOptions< MiddlewareHandler, typeof serveStatic, typeof walk >) ); appMain.get('/', (c) => { return c.text('Hello Hono!'); }); Deno.serve(/*{port:8007},*/ appMain.fetch);
@cis
also calledmod-by-cis
is acronym of my surname Cisowski (Cisowscy)hono-ftp
also calledhono-deno-ftp
- it was created to minimize unnecessary code duplication in each project - it is still a conceptual version that works correctly, but I have not checked all possible cases in which it could theoretically not work well
- 📦 JSR jsr.io/@cis/hono-ftp
- 📦 GITHUB github.com/mod-by-cis/hono-deno-ftp