# koa-static-server

> Static file serving middleware for koa with directory, rewrite and index support

Latest version **1.5.2** (published 2020-05-15) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: has types package; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.5.2 |
| Published | 2020-05-15 |
| First published | 2015-05-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/koa-static-server) |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 6.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 61 |
| Maintainers | pkoretic |
| Keywords | koa, middleware, file, static, sendfile, directory, server, folder |

## Links

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

## Dependencies (2)

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

## Alternatives

- [unionfs](https://npm.io/package/unionfs.md) — 2.2M weekly downloads
- [path-starts-with](https://npm.io/package/path-starts-with.md) — 35.9K weekly downloads
- [redzip](https://npm.io/package/redzip.md) — 1.2K weekly downloads
- [vscode-anymatch](https://npm.io/package/vscode-anymatch.md) — 848 weekly downloads
- [@ledgerhq/coin-filecoin](https://npm.io/package/@ledgerhq/coin-filecoin.md) — 793 weekly downloads

## Recent versions

- 1.5.2 (latest) — 2020-05-15
- 1.5.1 — 2020-05-09
- 1.5.0 — 2020-03-29
- 1.4.0 — 2018-12-28
- 1.3.4 — 2018-02-22
- 1.3.3 — 2018-01-24
- 1.3.2 — 2017-07-20
- 1.3.0 — 2017-07-20
- 1.2.1 — 2017-05-16
- 1.2.0 — 2017-05-13
- 1.1.0 — 2017-05-09
- 1.0.0 — 2016-10-16
- 0.1.8 — 2015-09-14
- 0.1.7 — 2015-09-14
- 0.1.6 — 2015-06-28
- … 6 more at https://npm.io/package/koa-static-server/versions

## README

# koa-static-server

[![GitHub license](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/pkoretic/koa-static-server/blob/master/LICENSE)  
[![NPM](https://nodei.co/npm/koa-static-server.png?downloads=true&downloadRank=true&stars=true)](https://www.npmjs.com/package/koa-static-server)

static file serving middleware for koa with directory, rewrite and index support

## Installation

```bash
$ npm install koa-static-server
```

## API

```js
var koa = require('koa')
var app = koa()
app.use(require('koa-static-server')(options))
```


### Options

 - `rootDir` {string} directory that is to be served
 - `rootPath` {string} optional rewrite path, (defaults to `"/"`)
 - `notFoundFile` {string} optional default file to serve if requested static is missing
 - `log` {boolean} request access log to console
 - `last` {boolean} don't execute any downstream middleware. (defaults to `true`)
 - `maxage` Browser cache max-age in milliseconds. (defaults to `0`)
 - `hidden` Allow transfer of hidden files. (defaults to `false`)
 - `index` Name of the index file to serve automatically when visiting root location. (defaults to `"index.html"`, use `""` to disable)
 - `gzip` Try to serve the gzipped version of a file automatically when `gzip`
is supported by a client and if the requested file with `.gz` extension exists.
(defaults to `true`)

## Example
See [examples](https://github.com/pkoretic/koa-static-server/tree/master/examples) for code examples

```js
// example 'web' directory
// web/index.html
// web/file.txt

var serve = require('koa-static-server')
var app = require('koa')()

// root index support
// GET /
// returns index.html
// GET /file.txt
// returns file.txt
app.use(serve({rootDir: 'web'}))

// folder support
// GET /web/
// returns /web/index.html
// GET /web/file.txt
// returns /web/file.txt
app.use(serve({rootDir: 'web', rootPath: '/web'}))

// index support
// GET /
// returns /file.txt
app.use(serve({rootDir: 'web', index: 'file.txt'}))

// rewrite support
// GET /web/
// returns 404
// GET /admin
// returns /admin/index.html
app.use(serve({rootDir: 'web', rootPath: '/admin'}))

app.listen(3000)

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

## Support

 * Issues - [open new issue](https://github.com/pkoretic/koa-static-server/issues)
 * mail - petar.koretic@gmail.com

## License

  MIT

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