Initial commit: upload services folder
This commit is contained in:
+124
@@ -0,0 +1,124 @@
|
||||
|
||||
5.0.0 / 2018-06-19
|
||||
==================
|
||||
|
||||
* bump deps
|
||||
|
||||
4.0.3 / 2018-05-17
|
||||
==================
|
||||
|
||||
* npm: disable package-lock
|
||||
* bump deps
|
||||
|
||||
4.0.2 / 2017-11-16
|
||||
==================
|
||||
|
||||
* Fix: `serve` mutates `opts` argument so it cannot be reused (#117)
|
||||
|
||||
4.0.1 / 2017-07-09
|
||||
==================
|
||||
|
||||
* Fix: throw error if error status not 404
|
||||
* fix `index: false` bug if path is directory
|
||||
|
||||
4.0.0 / 2017-07-03
|
||||
==================
|
||||
|
||||
* upgrade to koa-send@4
|
||||
* use async function
|
||||
|
||||
3.0.0 / 2016-03-24
|
||||
==================
|
||||
|
||||
* support koa 2.x
|
||||
* travis: test node@4+
|
||||
|
||||
2.0.0 / 2016-01-07
|
||||
==================
|
||||
|
||||
* bump koa-send@~3.1.0
|
||||
|
||||
1.5.2 / 2015-11-03
|
||||
==================
|
||||
|
||||
* Fix: default index could be disabled. Closes #41
|
||||
|
||||
1.5.1 / 2015-10-14
|
||||
==================
|
||||
|
||||
* Fix v1.4.x → 1.5.0 broken. Closes #53
|
||||
|
||||
1.5.0 / 2015-10-14
|
||||
==================
|
||||
|
||||
* update koa-send@2
|
||||
* update devDeps
|
||||
|
||||
1.4.9 / 2015-02-03
|
||||
==================
|
||||
|
||||
* only support GET and HEAD requests
|
||||
|
||||
1.4.8 / 2014-12-17
|
||||
==================
|
||||
|
||||
* support root = `.`
|
||||
|
||||
1.4.7 / 2014-09-07
|
||||
==================
|
||||
|
||||
* update koa-send
|
||||
|
||||
1.4.5 / 2014-05-05
|
||||
==================
|
||||
|
||||
* Fix response already handled logic - Koajs now defaults status == 404. See koajs/koa#269
|
||||
|
||||
1.4.4 / 2014-05-04
|
||||
==================
|
||||
|
||||
* Add two missing semicolons. Closes #24
|
||||
* Use bash syntax highlighting for install command. Closes #23
|
||||
* named generator function to help debugging. Closes #20
|
||||
|
||||
1.4.3 / 2014-02-11
|
||||
==================
|
||||
|
||||
* update koa-send
|
||||
|
||||
1.4.2 / 2014-01-07
|
||||
==================
|
||||
|
||||
* update koa-send
|
||||
|
||||
1.4.1 / 2013-12-30
|
||||
==================
|
||||
|
||||
* fix for koa 0.2.1. Closes #12
|
||||
|
||||
1.4.0 / 2013-12-20
|
||||
==================
|
||||
|
||||
* add: defer option - semi-breaking change
|
||||
|
||||
1.3.0 / 2013-12-11
|
||||
==================
|
||||
|
||||
* refactor to use koa-send
|
||||
* rename maxAge -> maxage
|
||||
* fix: don't bother responding if response already "handled"
|
||||
|
||||
1.2.0 / 2013-09-14
|
||||
==================
|
||||
|
||||
* add Last-Modified. Closes #5
|
||||
|
||||
1.1.1 / 2013-09-13
|
||||
==================
|
||||
|
||||
* fix upstream responses
|
||||
|
||||
1.1.0 / 2013-09-13
|
||||
==================
|
||||
|
||||
* rewrite without send
|
||||
+86
@@ -0,0 +1,86 @@
|
||||
# koa-static
|
||||
|
||||
[![NPM version][npm-image]][npm-url]
|
||||
[![Build status][travis-image]][travis-url]
|
||||
[![Test coverage][coveralls-image]][coveralls-url]
|
||||
[![Dependency Status][david-image]][david-url]
|
||||
[![License][license-image]][license-url]
|
||||
[![Downloads][downloads-image]][downloads-url]
|
||||
|
||||
Koa static file serving middleware, wrapper for [`koa-send`](https://github.com/koajs/send).
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
$ npm install koa-static
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
```js
|
||||
const Koa = require('koa');
|
||||
const app = new Koa();
|
||||
app.use(require('koa-static')(root, opts));
|
||||
```
|
||||
|
||||
* `root` root directory string. nothing above this root directory can be served
|
||||
* `opts` options object.
|
||||
|
||||
### Options
|
||||
|
||||
- `maxage` Browser cache max-age in milliseconds. defaults to 0
|
||||
- `hidden` Allow transfer of hidden files. defaults to false
|
||||
- `index` Default file name, defaults to 'index.html'
|
||||
- `defer` If true, serves after `return next()`, allowing any downstream middleware to respond first.
|
||||
- `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.
|
||||
- `br` Try to serve the brotli version of a file automatically when brotli is supported by a client and if the requested file with .br extension exists (note, that brotli is only accepted over https). defaults to true.
|
||||
- [setHeaders](https://github.com/koajs/send#setheaders) Function to set custom headers on response.
|
||||
- `extensions` Try to match extensions from passed array to search for file when no extension is sufficed in URL. First found is served. (defaults to `false`)
|
||||
|
||||
## Example
|
||||
|
||||
```js
|
||||
const serve = require('koa-static');
|
||||
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');
|
||||
```
|
||||
|
||||
### See also
|
||||
|
||||
- [koajs/conditional-get](https://github.com/koajs/conditional-get) Conditional GET support for koa
|
||||
- [koajs/compress](https://github.com/koajs/compress) Compress middleware for koa
|
||||
- [koajs/mount](https://github.com/koajs/mount) Mount `koa-static` to a specific path
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
|
||||
[npm-image]: https://img.shields.io/npm/v/koa-static.svg?style=flat-square
|
||||
[npm-url]: https://npmjs.org/package/koa-static
|
||||
[github-tag]: http://img.shields.io/github/tag/koajs/static.svg?style=flat-square
|
||||
[github-url]: https://github.com/koajs/static/tags
|
||||
[travis-image]: https://img.shields.io/travis/koajs/static.svg?style=flat-square
|
||||
[travis-url]: https://travis-ci.org/koajs/static
|
||||
[coveralls-image]: https://img.shields.io/coveralls/koajs/static.svg?style=flat-square
|
||||
[coveralls-url]: https://coveralls.io/r/koajs/static?branch=master
|
||||
[david-image]: http://img.shields.io/david/koajs/static.svg?style=flat-square
|
||||
[david-url]: https://david-dm.org/koajs/static
|
||||
[license-image]: http://img.shields.io/npm/l/koa-static.svg?style=flat-square
|
||||
[license-url]: LICENSE
|
||||
[downloads-image]: http://img.shields.io/npm/dm/koa-static.svg?style=flat-square
|
||||
[downloads-url]: https://npmjs.org/package/koa-static
|
||||
[gittip-image]: https://img.shields.io/gittip/jonathanong.svg?style=flat-square
|
||||
[gittip-url]: https://www.gittip.com/jonathanong/
|
||||
+73
@@ -0,0 +1,73 @@
|
||||
|
||||
'use strict'
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
const debug = require('debug')('koa-static')
|
||||
const { resolve } = require('path')
|
||||
const assert = require('assert')
|
||||
const send = require('koa-send')
|
||||
|
||||
/**
|
||||
* Expose `serve()`.
|
||||
*/
|
||||
|
||||
module.exports = serve
|
||||
|
||||
/**
|
||||
* Serve static files from `root`.
|
||||
*
|
||||
* @param {String} root
|
||||
* @param {Object} [opts]
|
||||
* @return {Function}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
function serve (root, opts) {
|
||||
opts = Object.assign({}, opts)
|
||||
|
||||
assert(root, 'root directory is required to serve files')
|
||||
|
||||
// options
|
||||
debug('static "%s" %j', root, opts)
|
||||
opts.root = resolve(root)
|
||||
if (opts.index !== false) opts.index = opts.index || 'index.html'
|
||||
|
||||
if (!opts.defer) {
|
||||
return async function serve (ctx, next) {
|
||||
let done = false
|
||||
|
||||
if (ctx.method === 'HEAD' || ctx.method === 'GET') {
|
||||
try {
|
||||
done = await send(ctx, ctx.path, opts)
|
||||
} catch (err) {
|
||||
if (err.status !== 404) {
|
||||
throw err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!done) {
|
||||
await next()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return async function serve (ctx, next) {
|
||||
await next()
|
||||
|
||||
if (ctx.method !== 'HEAD' && ctx.method !== 'GET') return
|
||||
// response is already handled
|
||||
if (ctx.body != null || ctx.status !== 404) return // eslint-disable-line
|
||||
|
||||
try {
|
||||
await send(ctx, ctx.path, opts)
|
||||
} catch (err) {
|
||||
if (err.status !== 404) {
|
||||
throw err
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
{
|
||||
"name": "koa-static",
|
||||
"description": "Static file serving middleware for koa",
|
||||
"repository": "koajs/static",
|
||||
"version": "5.0.0",
|
||||
"keywords": [
|
||||
"koa",
|
||||
"middleware",
|
||||
"file",
|
||||
"static",
|
||||
"sendfile"
|
||||
],
|
||||
"files": [
|
||||
"index.js"
|
||||
],
|
||||
"devDependencies": {
|
||||
"eslint": "^4.19.1",
|
||||
"eslint-config-standard": "^11.0.0",
|
||||
"eslint-plugin-import": "^2.12.0",
|
||||
"eslint-plugin-node": "^6.0.1",
|
||||
"eslint-plugin-promise": "^3.8.0",
|
||||
"eslint-plugin-standard": "^3.1.0",
|
||||
"istanbul": "^0.4.5",
|
||||
"koa": "^2.5.1",
|
||||
"mocha": "^5.2.0",
|
||||
"supertest": "^3.1.0"
|
||||
},
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"debug": "^3.1.0",
|
||||
"koa-send": "^5.0.0"
|
||||
},
|
||||
"scripts": {
|
||||
"lint": "eslint --fix .",
|
||||
"test": "mocha --harmony --reporter spec --exit",
|
||||
"test-cov": "node --harmony ./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha -- --exit",
|
||||
"test-travis": "node --harmony ./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha --report lcovonly -- --exit"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 7.6.0"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user