Static file serving middleware with router,wrapper for koa-send.
Static file serving middleware with router,wrapper for koa-send and support Multiple Router
$ npm install koa-static-router
app.use(static('public')) //default: {dir:public route:'/public'}
app.use(static({
dir:'public', //dir:static resource directory
router:'/' //router: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/'
}
]))
git clone [email protected]: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
}
]))