# koa-static-router

> Serving for koa-send to be a static server

Latest version **1.5.0** (published 2021-02-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install koa-static-router
pnpm add koa-static-router
yarn add koa-static-router
bun add koa-static-router
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.5.0 |
| Published | 2021-02-03 |
| First published | 2018-08-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 7.6.0 |
| Dependencies | 1 |
| Unpacked size | 5.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | daivonup@163.com |
| Maintainers | rise-devin |
| Keywords | koa, file, static, sendfile, router |

## Links

- npm: https://www.npmjs.com/package/koa-static-router
- Repository: https://github.com/AwesomeDevin/koa-static-router
- Homepage: https://github.com/AwesomeDevin/koa-static-router#readme
- Issues: https://github.com/AwesomeDevin/koa-static-router/issues
- npm.io page: https://npm.io/package/koa-static-router

## Dependencies (1)

- [koa-send](https://npm.io/package/koa-send.md) ^5.0.0

## Alternatives

- [express-promise-router](https://npm.io/package/express-promise-router.md) — 736.1K weekly downloads
- [next-usequerystate](https://npm.io/package/next-usequerystate.md) — 29.8K weekly downloads
- [@bitkyc08/opencodex](https://npm.io/package/@bitkyc08/opencodex.md) — 4.6K weekly downloads
- [lynkr](https://npm.io/package/lynkr.md) — 575 weekly downloads
- [baremetal.js](https://npm.io/package/baremetal.js.md) — 42 weekly downloads

## Recent versions

- 1.5.0 (latest) — 2021-02-03
- 1.4.4 — 2021-02-03
- 1.4.3 — 2021-02-03
- 1.4.2 — 2021-02-03
- 1.4.1 — 2021-02-03
- 1.4.0 — 2021-02-03
- 1.3.0 — 2019-05-08
- 1.2.0 — 2018-09-04
- 1.1.9 — 2018-09-04
- 1.1.8 — 2018-09-04
- 1.1.7 — 2018-08-03
- 1.1.6 — 2018-08-03
- 1.1.5 — 2018-08-03
- 1.1.4 — 2018-08-03
- 1.1.3 — 2018-08-03
- … 3 more at https://npm.io/package/koa-static-router/versions

## README

# koa-static-router
![](https://img.shields.io/badge/npm-1.1.3-blue.svg)
![](https://img.shields.io/badge/license-MIT-brightgreen.svg)


Static file serving middleware with router,wrapper for koa-send.【koa中间件,koa-static-router实现多个&&多层路由加载静态资源】

## Installation

```js
$ npm install koa-static-router
```

## Usage
#### Simple Router
```
app.use(static('public'))
```
#### A Single Router
```
 app.use(static({
     dir:'public',    //dir:static resource directory
     router:'/'    //router:router
 }))
```

#### Multiple Router 
> please make sure that routing is same length 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
![](https://github.com/Rise-Devin/koa-static-router/blob/master/img/public.png?raw=true)
Access localhost:3000/static/image/dir/2.png
![](https://github.com/Rise-Devin/koa-static-router/blob/master/img/static.png?raw=true)
```
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
}
]))
```

---
_Source: https://npm.io/package/koa-static-router · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
