Skip to content

serveStatic need optional parameter that allows to edit the route to file path #29

@renhiyama

Description

@renhiyama

Currently, serveStatic does this:

$ node src/index.js
Static file: ./.reejs/__reejs/deps/render/index.js is not found
Static file: ./.reejs/__reejs/.reejs/deps/render/index.js is not found
Static file: ./.reejs/__reejs/deps/react/index.js is not found
Static file: ./.reejs/__reejs/cache/cache.json is not found
^C
______________________________________________________________________

$ cat src/index.js
import { serve } from '@hono/node-server';
import { Hono } from 'hono';
import {serveStatic} from '@hono/node-server/serve-static;
const app = new Hono();
app.get('/', (c) => c.text('Hello Hono!'));                           
app.use('/__reejs/**', serveStatic({root: './.reejs/'}));

serve(app)

My files are saved inside .reejs folder, and not inside .reejs/__reejs folder.

Suggested fix: add a new parameter called rewritePath

app.use(
  '/__reejs/*',
  serveStatic({ root: './.reejs/', rewritePath: (path: string) => path.replace(/^\/__reejs/, '') })
)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions