DEV Community

Alexander Demin
Alexander Demin

Posted on

2

Serve file system browser as a web page

This demo application exposes the /fs/ endpoint serving the index of the file system.

The application uses Deno runtime, Hono web framework and nunjucks templates.

Usage

deno task dev
Enter fullscreen mode Exit fullscreen mode

Implementation

The crucial part of the application. The complete source is in the repo.

app.get(FS + "/*", (c) => {
    const path_ = decodeURI(c.req.path);
    const path = resolve(join("/", path_.slice(FS.length), "/"));
    const stat = Deno.statSync(path);
    if (stat.isDirectory) return c.html(directory(path));
    else {
        const { content, type } = file(path);
        return new Response(content, { headers: { "content-type": type } });
    }
});
Enter fullscreen mode Exit fullscreen mode

The example of the page

screenshot

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay