koa-static
Advanced tools
Comparing version 2.0.0 to 3.0.0
3.0.0 / 2016-03-24 | ||
================== | ||
* support koa 2.x | ||
* travis: test node@4+ | ||
2.0.0 / 2016-01-07 | ||
@@ -3,0 +9,0 @@ ================== |
28
index.js
@@ -8,5 +8,5 @@ | ||
const debug = require('debug')('koa-static'); | ||
const resolve = require('path').resolve; | ||
const assert = require('assert'); | ||
const debug = require('debug')('koa-static'); | ||
const send = require('koa-send'); | ||
@@ -40,19 +40,23 @@ | ||
if (!opts.defer) { | ||
return function *serve(next){ | ||
if (this.method == 'HEAD' || this.method == 'GET') { | ||
if (yield send(this, this.path, opts)) return; | ||
return function serve(ctx, next){ | ||
if (ctx.method == 'HEAD' || ctx.method == 'GET') { | ||
return send(ctx, ctx.path, opts).then(done => { | ||
if (!done) { | ||
return next(); | ||
} | ||
}); | ||
} | ||
yield* next; | ||
return next(); | ||
}; | ||
} | ||
return function *serve(next){ | ||
yield* next; | ||
return function serve(ctx, next){ | ||
return next().then(() => { | ||
if (ctx.method != 'HEAD' && ctx.method != 'GET') return; | ||
// response is already handled | ||
if (ctx.body != null || ctx.status != 404) return; | ||
if (this.method != 'HEAD' && this.method != 'GET') return; | ||
// response is already handled | ||
if (this.body != null || this.status != 404) return; | ||
yield send(this, this.path, opts); | ||
return send(ctx, ctx.path, opts); | ||
}); | ||
}; | ||
} |
@@ -5,3 +5,3 @@ { | ||
"repository": "koajs/static", | ||
"version": "2.0.0", | ||
"version": "3.0.0", | ||
"keywords": [ | ||
@@ -18,4 +18,4 @@ "koa", | ||
"devDependencies": { | ||
"istanbul-harmony": "0", | ||
"koa": "1", | ||
"istanbul": "0", | ||
"koa": "2", | ||
"mocha": "2", | ||
@@ -27,3 +27,3 @@ "supertest": "1" | ||
"debug": "*", | ||
"koa-send": "~3.1.0" | ||
"koa-send": "^3.2.0" | ||
}, | ||
@@ -30,0 +30,0 @@ "scripts": { |
@@ -10,5 +10,4 @@ # koa-static | ||
Koa static file serving middleware, wrapper for [`koa-send`](https://github.com/koajs/send). | ||
Static file serving middleware. | ||
## Installation | ||
@@ -36,3 +35,4 @@ | ||
- `index` Default file name, defaults to 'index.html' | ||
- `defer` If true, serves after `yield next`, allowing any downstream middleware to respond first. | ||
- `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. | ||
@@ -60,2 +60,8 @@ ## Example | ||
### 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 | ||
@@ -62,0 +68,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6315
48
84
+ Addeddebug@2.6.9(transitive)
+ Addedkoa-send@3.3.0(transitive)
+ Addedms@2.0.0(transitive)
- Removedkoa-send@3.1.1(transitive)
Updatedkoa-send@^3.2.0