1.0.2 • Published 6 years ago

koa-static-prefix v1.0.2

Weekly downloads
39
License
MIT
Repository
-
Last release
6 years ago

koa-static-prefix

base on koa-static add 'prefix path'

NPM version Build status Test coverage Dependency Status License Downloads

Koa static file serving middleware, wrapper for koa-send.

addr: https://github.com/zhoushirong/koa-staitc-prefix.git

Installation

$ npm install koa-static-prefix

API

const Koa = require('koa');
const app = new Koa();
app.use(require('koa-static-prefix')(root, opts));
  • root root directory string. nothing above this root directory can be served
  • opts options object.

Example

const serve = require('koa-static-prefix');
const Koa = require('koa');
const app = new Koa();

// $ GET /package.json
app.use(serve('.'));

// $ GET /hello.txt
app.use(serve('test/fixtures'));

// or use absolute paths
app.use(serve(__dirname + '/test/fixtures'));

app.listen(3000);

console.log('listening on port 3000');

app.use(serve(__dirname + '/test/fixtures', { pathPrefix:'/test' }));