aboutsummaryrefslogtreecommitdiff
path: root/node_modules/@shellscape/koa-static
diff options
context:
space:
mode:
authorruki <waruqi@gmail.com>2018-11-08 00:38:48 +0800
committerruki <waruqi@gmail.com>2018-11-07 21:53:09 +0800
commit26105034da4fcce7ac883c899d781f016559310d (patch)
treec459a5dc4e3aa0972d9919033ece511ce76dd129 /node_modules/@shellscape/koa-static
parent2c77f00f1a7ecb6c8192f9c16d3b2001b254a107 (diff)
downloadxmake-docs-26105034da4fcce7ac883c899d781f016559310d.tar.gz
xmake-docs-26105034da4fcce7ac883c899d781f016559310d.zip
switch to vuepress
Diffstat (limited to 'node_modules/@shellscape/koa-static')
-rw-r--r--node_modules/@shellscape/koa-static/History.md113
-rw-r--r--node_modules/@shellscape/koa-static/Readme.md86
-rw-r--r--node_modules/@shellscape/koa-static/index.js73
-rw-r--r--node_modules/@shellscape/koa-static/legacy/index.js92
-rw-r--r--node_modules/@shellscape/koa-static/package.json53
5 files changed, 417 insertions, 0 deletions
diff --git a/node_modules/@shellscape/koa-static/History.md b/node_modules/@shellscape/koa-static/History.md
new file mode 100644
index 00000000..f5dbcab1
--- /dev/null
+++ b/node_modules/@shellscape/koa-static/History.md
@@ -0,0 +1,113 @@
+
+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
diff --git a/node_modules/@shellscape/koa-static/Readme.md b/node_modules/@shellscape/koa-static/Readme.md
new file mode 100644
index 00000000..16c32eaa
--- /dev/null
+++ b/node_modules/@shellscape/koa-static/Readme.md
@@ -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/
diff --git a/node_modules/@shellscape/koa-static/index.js b/node_modules/@shellscape/koa-static/index.js
new file mode 100644
index 00000000..02355ef0
--- /dev/null
+++ b/node_modules/@shellscape/koa-static/index.js
@@ -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
+ }
+ }
+ }
+}
diff --git a/node_modules/@shellscape/koa-static/legacy/index.js b/node_modules/@shellscape/koa-static/legacy/index.js
new file mode 100644
index 00000000..fe21365b
--- /dev/null
+++ b/node_modules/@shellscape/koa-static/legacy/index.js
@@ -0,0 +1,92 @@
+'use strict';
+/**
+ * Module dependencies.
+ */
+
+function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } function _next(value) { step("next", value); } function _throw(err) { step("throw", err); } _next(); }); }; }
+
+const debug = require('debug')('koa-static');
+
+const {
+ resolve
+} = require('path');
+
+const assert = require('assert');
+
+const send = require("@shellscape/koa-send/legacy");
+/**
+ * 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 (
+ /*#__PURE__*/
+ function () {
+ var _serve = _asyncToGenerator(function* (ctx, next) {
+ let done = false;
+
+ if (ctx.method === 'HEAD' || ctx.method === 'GET') {
+ try {
+ done = yield send(ctx, ctx.path, opts);
+ } catch (err) {
+ if (err.status !== 404) {
+ throw err;
+ }
+ }
+ }
+
+ if (!done) {
+ yield next();
+ }
+ });
+
+ return function serve(_x, _x2) {
+ return _serve.apply(this, arguments);
+ };
+ }()
+ );
+ }
+
+ return (
+ /*#__PURE__*/
+ function () {
+ var _serve2 = _asyncToGenerator(function* (ctx, next) {
+ yield 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 {
+ yield send(ctx, ctx.path, opts);
+ } catch (err) {
+ if (err.status !== 404) {
+ throw err;
+ }
+ }
+ });
+
+ return function serve(_x3, _x4) {
+ return _serve2.apply(this, arguments);
+ };
+ }()
+ );
+}
diff --git a/node_modules/@shellscape/koa-static/package.json b/node_modules/@shellscape/koa-static/package.json
new file mode 100644
index 00000000..24a4d5b9
--- /dev/null
+++ b/node_modules/@shellscape/koa-static/package.json
@@ -0,0 +1,53 @@
+{
+ "name": "@shellscape/koa-static",
+ "description": "Static file serving middleware for koa",
+ "repository": "shellscape/koa-static",
+ "version": "4.0.5",
+ "keywords": [
+ "koa",
+ "middleware",
+ "file",
+ "static",
+ "sendfile"
+ ],
+ "files": [
+ "index.js",
+ "legacy/index.js"
+ ],
+ "publishConfig": {
+ "access": "public"
+ },
+ "devDependencies": {
+ "@babel/cli": "^7.0.0-beta.39",
+ "@babel/core": "^7.0.0-beta.39",
+ "@babel/polyfill": "^7.0.0-beta.39",
+ "@babel/preset-env": "^7.0.0-beta.39",
+ "@babel/register": "^7.0.0-beta.39",
+ "babel-plugin-module-resolver": "^3.0.0",
+ "eslint": "^4.1.1",
+ "eslint-config-standard": "^10.2.1",
+ "eslint-plugin-import": "^2.6.1",
+ "eslint-plugin-node": "^5.1.0",
+ "eslint-plugin-promise": "^3.5.0",
+ "eslint-plugin-standard": "^3.0.1",
+ "istanbul": "^0.4.5",
+ "koa": "^2.3.0",
+ "mocha": "^3.4.2",
+ "supertest": "^3.0.0"
+ },
+ "license": "MIT",
+ "dependencies": {
+ "debug": "^2.6.8",
+ "@shellscape/koa-send": "^4.1.0"
+ },
+ "scripts": {
+ "lint": "eslint --fix .",
+ "prepublishOnly": "babel index.js --out-file legacy/index.js",
+ "test": "npm run prepublishOnly && mocha --harmony --reporter spec",
+ "test-cov": "node --harmony ./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha",
+ "test-travis": "node --harmony ./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha --report lcovonly"
+ },
+ "engines": {
+ "node": ">= 6"
+ }
+}