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)

Cloudinary image

Video API: manage, encode, and optimize for any device, channel or network condition. Deliver branded video experiences in minutes and get deep engagement insights.

Learn more

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay