Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update readme with an example of proper "root" when using serveStatic #173

Merged
merged 2 commits into from
Jun 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,28 @@ import { serveStatic } from '@hono/node-server/serve-static'
app.use('/static/*', serveStatic({ root: './' }))
```

Note that `root` must be _relative_ to the current working directory - absolute paths are not supported.
Note that `root` must be _relative_ to the current working directory from which the app was started. Absolute paths are not supported.

This can cause confusion when running your application locally.

Imagine your project structure is:

```
my-hono-project/
src/
index.ts
static/
index.html
```

Typically, you would run your app from the project's root directory (`my-hono-project`),
so you would need the following code to serve the `static` folder:

```ts
app.use('/static/*', serveStatic({ root: './static' }))
```

Notice that `root` here is not relative to `src/index.ts`, rather to `my-hono-project`.

### Options

Expand Down
2 changes: 1 addition & 1 deletion src/serve-static.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { getMimeType } from 'hono/utils/mime'

export type ServeStaticOptions = {
/**
* Root path, relative to current working directory. (absolute paths are not supported)
* Root path, relative to current working directory from which the app was started. Absolute paths are not supported.
*/
root?: string
path?: string
Expand Down