Socket
Socket
Sign inDemoInstall

koa-static-serve

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

koa-static-serve

static serve middlware for koa


Version published
Weekly downloads
6
increased by500%
Maintainers
1
Weekly downloads
 
Created
Source

static serve middlware for koa

Build Status Coverage Status npm Github Releases

  • ETag The module use weak etag, which is derived from last-modified time and file length.

  • Last-Modified File last-modified time.

Installation

$ npm i koa-static-serve

Examples

View the ./examples directory for working examples.

API

serve(staticPath, options)

const Koa = require('koa');
const path = require('path');
const app = new Koa();
const serve = require('koa-static-serve');
const staticPath = path.join(__dirname, '..');
app.use(serve(staticPath, {
  maxAge: 3600,
  sMaxAge: 600,
  headers: {
    'X-Server': 'koa-static-serve',
  },
  dotfiles: 'allow',
  denyQuerystring: true,
  etag: false,
  lastModified: false,
  '404': 'next',
  extname: ['.html'],
}));
const port = process.env.PORT || 10000;
app.listen(port);
console.dir('server listen on:' + port);

staticPath static file path

options

  • maxAge Static file's http response header, Cache-Control max-age, default is 0.

  • sMaxAge Static file's http response header, Cache-Control s-maxage for cache application(eg. varnish). If not set, it will be Math.min(3600, maxAge).

  • headers The default header.

  • dotfiles Dot file access permission, it can be 'allow', 'deny', 'ignore'. Default is 'ignore'.

  • denyQuerystring Deny query string, default is false. If using a http cache server(varnish) for the static files, query string should be denied. Otherwise there will be different cache for the same file.

  • charset Default content charset.

  • etag Enable or disable etag generation, default is true.

  • lastModified Set the Last-Modified header to the last modified date of the file on the OS, default is true.

  • 404 Set not found handler. If set 'next', it will call next when not found, otherwise will throw an error (404).

  • extname Set default extname.

License

MIT

Keywords

FAQs

Package last updated on 01 Oct 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc