1.4.3 • Published 2 years ago

@awesomeorganization/static-handler v1.4.3

Weekly downloads
103
License
MIT
Repository
github
Last release
2 years ago

static-handler

:boom: ESM The static handler for Node.js according to rfc7230, rfc7231, rfc7232, rfc7233, rfc7234 and whatwg


GitHub Workflow Codacy CodeFactor Snyk Depfu npms.io


Install

npm install @awesomeorganization/static-handler

Example

Full example in /example folder.

const rewriteMiddleware = rewriteHandler({
  rules: [
    {
      pattern: '^/old-files/(.*)',
      replacement: '/files/$1',
      statusCode: REDIRECT_STATUS_CODES.MOVED_PERMANENTLY,
    },
    {
      pattern: '(.*)/$',
      replacement: '$1/index.txt',
    },
  ],
})
const staticMiddleware = await staticHandler({
  directoryPath: './static',
})
http({
  handlers: {
    request(request, response) {
      rewriteMiddleware.handle({
        request,
        response,
      })
      staticMiddleware.handle({
        request,
        response,
      })
    },
  },
  listenOptions: {
    host: '127.0.0.1',
    port: 3000,
  },
})
// TRY
// http://127.0.0.1:3000/
// http://127.0.0.1:3000/files/
// http://127.0.0.1:3000/files/somefile.txt
// http://127.0.0.1:3000/old-files/
// http://127.0.0.1:3000/old-files/somefile.txt
1.4.3

2 years ago

1.4.2

2 years ago

1.4.1

2 years ago

1.4.0

2 years ago

1.2.0

2 years ago

1.3.0

2 years ago

1.1.0

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago

0.2.7

3 years ago

0.2.6

3 years ago

0.2.5

3 years ago

0.2.4

3 years ago

0.2.3

3 years ago

0.2.2

3 years ago

0.2.1

3 years ago

0.2.0

3 years ago

0.1.9

4 years ago

0.1.8

4 years ago

0.1.7

4 years ago

0.1.6

4 years ago

0.1.5

4 years ago

0.1.4

4 years ago

0.1.2

4 years ago

0.1.3

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago