1.3.2 • Published 10 months ago

passing-notes-static v1.3.2

Weekly downloads
1
License
MIT
Repository
github
Last release
10 months ago

passing-notes-static

npm CI Status dependencies Status devDependencies Status

A static file middleware for passing-notes.

Usage

Install passing-notes-static by running:

yarn add passing-notes-static

Then, compose it with other middleware, or at least a default handler:

import {compose} from 'passing-notes'
import serveStatic from 'passing-notes-static'

export default compose(
  serveStatic('./'),
  () => () => ({status: 404})
)

serveStatic will resolve files within and relative to the given directory. When it can't find a file, it will delegate to the next middleware.

In addition, serveStatic supports serving from a lookup of file path to fixed string. Extra whitespaces from indentation are stripped out:

import {compose} from 'passing-notes'
import serveStatic from 'passing-notes-static'

export default compose(
  serveStatic({
    'index.html': `
      <!doctype html>
      <script type="module" src="/app/index.js"></script>
    `,
    'app/index.js': `
      window.document.body.innerHTML = '<p>Hello World!</p>'
    `
  }),
  () => () => ({status: 404})
)

Optionally, a baseUrl can be provided as second argument to "mount" the directory to a URL subpath. This can be used to route different URLs to different directories on the file system:

import {compose} from 'passing-notes'
import serveStatic from 'passing-notes-static'

export default compose(
  serveStatic({
    'index.html': `
      <!doctype html>
      <script type="module" src="/app/index.js"></script>
    `
  }, '/'),
  serveStatic('./src', '/assets/js'),
  serveStatic('./images', '/assets/images'),
  () => () => ({status: 404})
)
1.3.2

10 months ago

1.3.1

10 months ago

1.3.0

1 year ago

1.2.3

2 years ago

1.2.2

2 years ago

1.2.1

3 years ago

1.2.0

3 years ago

1.1.2

3 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.0

4 years ago