Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

koa-simple-static

Package Overview
Dependencies
Maintainers
1
Versions
96
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

koa-simple-static

Simple caching static file server for Koa 2.

  • 0.4.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
decreased by-88.89%
Maintainers
1
Weekly downloads
 
Created
Source

Koa Simple Static

Simple caching static file server for Koa 2.


Fork of koa-static-cache with better options.

Installation

npm i -S koa-simple-static

Usage

app.use(serve({
  dir: process.cwd()
}))

If you're on Node < 8.0.0, you'll need to use Babel in front of your server.

require('babel-register')({
  babelrc: false,
  presets: [ require('babel-preset-latest-minimal') ]
})
require('./server')

Options

  • dir : str — directory you want to serve
  • maxAge : ?number = 0 — cache control max age (in seconds)
  • gzip : ?bool = false — compress with gzip when request's accept-encoding includes gzip
  • extraHeaders : ?Object[] — any extra headers you wish to set for requests served by this module
    • The format for this is [ { 'Link': '</foo.js>; rel=preload; as=script' }, { 'Set-Cookie': 'foo=bar; path=/;' } ]

Example

import serve from 'koa-simple-static'
import { resolve } from 'path'
import Koa from 'koa'

const app = new Koa()
const port = process.env.PORT || 4444

app.use(serve({
  dir: resolve(__dirname, 'public'),
  gzip: true,
  extraHeaders: [ { 'X-Something-Whatever': 'foo, bar' } ]
}))

app.listen(port)
console.log(`Serving on ${port}!`)

Contributing

  • Please do, if you want! I'll consider any PRs, but no promises.
  • Notes:
    • This project uses Flow.
    • It will be easiest if you have your editor configured to work with eslint and flow.
    • Please run tests!
    • Please add tests, if you're adding functionality.
    • My top priorities right now:
      • Using Node's zlib and fs instead of mz

License

MIT

Keywords

FAQs

Package last updated on 25 Jun 2017

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