AwesomeDevin / koa-static-router

Static file serving middleware with router,wrapper for koa-send.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

koa-static-router

Static file serving middleware with router,wrapper for koa-send and support Multiple Router

Installation

$ npm install koa-static-router

Usage

Simple Router

app.use(static('public'))      //default: {dir:public  route:'/public'}

Single Router

 app.use(static({
     dir:'public',    //dir:static resource directory
     router:'/'    //router:router
 }))

Multiple Router

please make sure that routing length is the same when you choose Multiple Router

'/static/' - >routing length = 1

'/static/image1/' - >routing length =2

app.use(static([
    {
    dir:'public',     //dir:static resource directory
    router:'/public/'    //router:router
},{
    dir:'static',
    router:'/static/'  
}
]))

Example

git clone git@github.com:Rise-Devin/koa-static-router.git
cd koa-static-router
npm install 
npm start

Access localhost:3000/public/image/dir/1.png Access localhost:3000/static/image/dir/2.png

const static = require('koa-static-router');

//   A Single Router
// app.use(static({
//     dir:'public',
//     router:'/static/'   
// }))


//Multiple Router
app.use(static([
    {
    dir:'public',     
    router:'/public/image/'   //routing length = 2
},{
    dir:'static',
    router:'/static/image/'   //routing length = 2
}
]))

About

Static file serving middleware with router,wrapper for koa-send.


Languages

Language:JavaScript 70.2%Language:HTML 29.8%