Skip to content

bpcloud/middleware-koa-static

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

koa static middleware in bpframework.

Middleware specification

https://github.com/bpcloud/middleware

usage

Setup.

import { Application } from 'bpframework';
import * as middleware_static from '@bpframework/middleware-koa-static';

let cfg = {
  root: 'resource',       // file root directory.
  maxage: 30 * 24 * 60 * 60 * 1000, // Browser cache max-age in milliseconds. defaults to 0
  hidden: false,                    // Allow transfer of hidden files. defaults to false
  index: 'index.html',              // Default file name, defaults to 'index.html'
  gzip: true,                       // Try to serve the gzipped version of a file automatically when gzip is supported by a client and if the requested file with .gz extension exists. defaults to true.
  br: true,                         // Try to serve the brotli version of a file automatically when brotli is supported by a client and if the requested file with .br extension exists (note, that brotli is only accepted over https). defaults to true.
  setHeaders: (res: any, path: string, stats: any) => void, // Function to set custom headers on response. Alterations to the headers need to occur within this function, and not after the response has started. This is because the headers are sent after the file is determined, and before the data is sent.
  extensions: ['pdf'], Try to match extensions from passed array to search for file when no extension is sufficed in URL. First found is served. (defaults to `false`)
};

Application.use(middleware_static.middleware(cfg))
Application.runKoa(...);

About

koa static middleware in bpframework.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors