Skip to content

Conversation

@nakasyou
Copy link
Contributor

@nakasyou nakasyou commented Aug 21, 2024

It is work in progress.

I'll propose unified FS APIs. I'm trying implementing.

Motivation

JavaScript runtimes have different APIs to access file system. So Hono has wrapper in serveStatic and SSG Helper. They should be merged I think. Therefore I'll propose it.

Hono is just Web application framework but I'm sure that middleware creators can create more powerful middleware.

Web Standard

Hono follows Web Standard APIs. This PR will use WHATWG File System Access API (Spec, MDN).

However File System API is formulated for browsers, features for using local filesystem is sometimes missing. (e.g., Get absolute path from entry) So I'm going to extend API interface.

API Plans/Ideas

Open dir/file:

import { openDir, openFile } from 'hono/deno'

const dir = openDir('./public') // It's FileSystemDirectoryHandle but extended
const dir = openFile('./public/example.txt') // It's FileSystemFileHandle but extended

Serve static:

import { openDir, openFile } from 'hono/deno'
import { serveStatic } from 'hono/serve-static'

app.use('*', serveStatic({
  root: openDir('./public')
})
app.get('/favicon.ico', serveStatic({
  file: openFile('./assets/favicon.ico')
})

SSG:

import { toSSG } from 'hono/ssg'
import { openDir } from 'hono/deno'

toSSG(app, openDir('./dist'))

Progress

Currently it's almost an idea.

Runtimes

  • Deno
    • readDir (without file access)
    • readFile
  • Bun
  • Node.js

Features

  • SSG
  • Serve-Static

I want forward compatibility.

The author should do the following, if applicable

  • Add tests
  • Run tests
  • bun run format:fix && bun run lint:fix to format the code
  • Add TSDoc/JSDoc to document the code

@nakasyou nakasyou marked this pull request as draft August 21, 2024 14:23
@yusukebe
Copy link
Member

yusukebe commented Sep 6, 2024

@nakasyou
Copy link
Contributor Author

nakasyou commented Sep 7, 2024

@yusukebe
You can implement adapter for those.
Or, do you mean to make an API similar to this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants