0.4.35 • Published 1 month ago

@wooksjs/http-static v0.4.35

Weekly downloads
-
License
MIT
Repository
github
Last release
1 month ago

Wooks Serve File

!!! This is work-in-progress library, breaking changes are expected !!!

Wooks Serve File is composable static file server for @wooksjs/event-http.

serveFile returns a readable stream and prepares all the neccessary response headers (like content-length, content-type etc).

  • ✅ returns a readable stream
  • ✅ prepares all the neccessary response headers (like content-length, content-type etc)
  • ✅ can handle etag
  • ✅ can handle ranges

Installation

npm install @wooksjs/http-static

Usage

import { serveFile } from '@wooksjs/http-static'
// ...
serveFile(filePath, options)

serveFile options

{
    // Any header to add
    headers?: Record<string, string>,

    // Cache-Control header
    cacheControl?: TCacheControl,

    // Expires header
    expires?: Date | string | number,

    // when true a header "Pragma: no-cache" will be added
    pragmaNoCache?: boolean,

    // the base directory path
    baseDir?: string,

    // default extension will be added to the filePath
    defaultExt?: string,

    // when true lists files in directory
    listDirectory?: boolean,

    // put 'index.html'
    // to automatically serve it from the folder
    index?: string,
}

Built-in file server example:

import { useRouteParams } from 'wooks'
import { serveFile } from '@wooksjs/http-static'
app.get('static/*', () => {
  const { get } = useRouteParams()
  return serveFile(get('*'), { cacheControl: { maxAge: '10m' } })
})

cacheControl here is the same object as used in useSetCacheControl().setCacheControl({ ... }) from @wooksjs/composables

Documentation

To check out docs, visit wooks.moost.org.

0.4.35

1 month ago

0.4.33

1 month ago

0.4.34

1 month ago

0.4.31

1 month ago

0.4.32

1 month ago

0.4.30

2 months ago

0.4.28

3 months ago

0.4.29

3 months ago

0.4.27

3 months ago

0.4.26

3 months ago

0.4.24

4 months ago

0.4.23

4 months ago

0.4.22

4 months ago

0.4.20

4 months ago

0.4.21

4 months ago

0.4.18

4 months ago

0.4.17

4 months ago

0.4.15

4 months ago

0.4.16

4 months ago

0.4.14

4 months ago

0.4.13

5 months ago

0.4.12

5 months ago

0.4.10

5 months ago

0.4.11

5 months ago

0.4.9

6 months ago

0.4.8

7 months ago

0.3.8

10 months ago

0.3.7

10 months ago

0.3.9

10 months ago

0.3.12

10 months ago

0.3.11

10 months ago

0.3.10

10 months ago

0.4.5

7 months ago

0.4.4

7 months ago

0.4.7

7 months ago

0.4.6

7 months ago

0.4.1

9 months ago

0.4.0

9 months ago

0.4.3

7 months ago

0.4.2

9 months ago

0.2.23

12 months ago

0.2.22

12 months ago

0.2.21

12 months ago

0.2.20

12 months ago

0.2.19

12 months ago

0.3.0

12 months ago

0.3.6

11 months ago

0.3.5

11 months ago

0.3.2

12 months ago

0.3.1

12 months ago

0.3.4

11 months ago

0.3.3

12 months ago

0.2.16

1 year ago

0.2.15

1 year ago

0.2.14

1 year ago

0.2.18

1 year ago

0.2.17

1 year ago

0.2.13

1 year ago

0.2.12

1 year ago

0.2.11

1 year ago

0.2.10

1 year ago

0.2.9

1 year ago

0.2.8

1 year ago

0.2.7

1 year ago

0.2.6

1 year ago

0.2.5

1 year ago

0.2.4

1 year ago

0.2.3

1 year ago

0.2.2

1 year ago

0.2.1

1 year ago

0.1.0

1 year ago