pambda-serve-static

0.1.0 • Public • Published

pambda-serve-static

Serve static files for AWS Lambda.

Installation

npm i pambda-serve-static

Usage

const { compose, createLambda } = require('pambda');
const { binarySupport } = require('pambda-binary-support');
const { cache } = require('pambda-cache');
const { serveStatic } = require('pambda-serve-static');

exports.handler = createLambda(
  compose(
    cache(),
    binarySupport({
      binaryMediaTypes: [ 'image/*' ],
    }),
    serveStatic('public', {
      basePath: '/',
      index: [ 'index.htm', 'index.html' ],
      maxAge: 60 * 60 * 24,
    })
  )
);

When serving binary files like images, you need to combine with pambda-binary-support.

serveStatic(root, options)

  • root
    • The path on the file system of the root directory where static files are stored.
  • options.basePath
    • The base path that serves static files.
  • options.index
    • The file name of the file to return when the directory is requested.
  • options.maxAge
    • Specify the time in seconds for which the response cache is available.

License

MIT

Readme

Keywords

Package Sidebar

Install

npm i pambda-serve-static

Weekly Downloads

0

Version

0.1.0

License

MIT

Unpacked Size

5.75 kB

Total Files

4

Last publish

Collaborators

  • nak2k