Skip to content

Commit 4a20888

Browse files
v1rtlv1rtl
authored andcommitted
fix static handler args
1 parent 5ea2f90 commit 4a20888

4 files changed

Lines changed: 10 additions & 8 deletions

File tree

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ yarn add @tinyhttp/app
4343

4444
You can see the documentation [here](https://tinyhttp.v1rtl.site/docs).
4545

46-
## Example
46+
## Get Started
47+
48+
The app structure is quite similar to Express, except that you need to import `App` from `@tinyhttp/app` instead of default import from `express`.
4749

4850
```ts
4951
import { App } from '@tinyhttp/app'

examples/basic/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { App } from '@tinyhttp/app'
2-
import staticFolder from '@tinyhttp/static'
2+
import { staticHandler } from '@tinyhttp/static'
33
import logger from '@tinyhttp/logger'
44

55
const app = new App()
@@ -16,5 +16,5 @@ app
1616
`)
1717
})
1818
.use(logger())
19-
.use(staticFolder())
19+
.use(staticHandler('./'))
2020
.listen(3000)

packages/static/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@tinyhttp/static",
3-
"version": "0.1.26",
3+
"version": "0.1.27",
44
"description": "tinyhttp static middleware",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

packages/static/src/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ export type StaticHandlerOptions = Partial<{
1313
recursive: boolean
1414
}>
1515

16-
export const staticHandler = (
17-
dir = process.cwd(),
18-
{ prefix = '/', recursive = false }: StaticHandlerOptions
19-
): AsyncHandler => {
16+
export const staticHandler = (dir = process.cwd(), opts?: StaticHandlerOptions): AsyncHandler => {
2017
return async (req: Request, res: Response, next?: NextFunction) => {
2118
let files: string[]
2219

20+
const prefix = opts.prefix || '/'
21+
const recursive = opts.recursive || false
22+
2323
if (recursive) {
2424
files = (
2525
await recursiveReaddir(dir, {

0 commit comments

Comments
 (0)