koa-add-trailing-slashes
Advanced tools
Comparing version 1.1.0 to 2.0.0
24
index.js
@@ -20,25 +20,25 @@ 'use strict'; | ||
return function* (next) { | ||
return async function(ctx, next) { | ||
if (opts.defer) { | ||
yield next; | ||
await next(); | ||
} | ||
var path; | ||
let path; | ||
// We have already done a redirect and we will continue if we are in chained mode | ||
if (opts.chained && this.status === 301) { | ||
path = getPath(this.response.get('Location'), this.querystring); | ||
} else if (this.status !== 301) { | ||
path = getPath(this.originalUrl, this.querystring); | ||
if (opts.chained && ctx.status === 301) { | ||
path = getPath(ctx.response.get('Location'), ctx.querystring); | ||
} else if (ctx.status !== 301) { | ||
path = getPath(ctx.originalUrl, ctx.querystring); | ||
} | ||
if (path && noBodyOrIndex(this.status, this.body, path, opts.index) && missingSlash(path)) { | ||
var query = this.querystring.length ? '?' + this.querystring : ''; | ||
if (path && noBodyOrIndex(ctx.status, ctx.body, path, opts.index) && missingSlash(path)) { | ||
const query = ctx.querystring.length ? '?' + ctx.querystring : ''; | ||
this.status = 301; | ||
this.redirect(path + '/' + query); | ||
ctx.status = 301; | ||
ctx.redirect(path + '/' + query); | ||
} | ||
if (!opts.defer) { | ||
yield next; | ||
await next(); | ||
} | ||
@@ -45,0 +45,0 @@ }; |
{ | ||
"name": "koa-add-trailing-slashes", | ||
"version": "1.1.0", | ||
"version": "2.0.0", | ||
"description": "Koa middleware that makes sure all requests have a trailing slashes", | ||
@@ -10,3 +10,3 @@ "main": "index.js", | ||
"test:unit": "mocha test", | ||
"test:coverage": "node --harmony node_modules/istanbul/lib/cli.js cover _mocha -- test" | ||
"test:coverage": "nyc --reporter=lcov --reporter=text mocha" | ||
}, | ||
@@ -29,8 +29,10 @@ "repository": { | ||
"coveralls": "~2.11.6", | ||
"eslint": "~1.10.3", | ||
"eslint-config-vgno": "~5.0.0", | ||
"eslint": "~4.16.0", | ||
"eslint-config-vgno": "~7.0.0", | ||
"expect": "~1.13.4", | ||
"istanbul": "~0.4.2", | ||
"mocha": "~2.3.4" | ||
"koa": "^2.4.1", | ||
"mocha": "~2.3.4", | ||
"nyc": "^11.4.1", | ||
"supertest": "^3.0.0" | ||
} | ||
} |
@@ -14,4 +14,4 @@ # koa-add-trailing-slashes | ||
```js | ||
var koa = require('koa'); | ||
var app = koa(); | ||
var Koa = require('koa'); | ||
var app = new Koa(); | ||
app.use(require('koa-add-trailing-slashes')(opts)); | ||
@@ -31,10 +31,10 @@ ``` | ||
```js | ||
var koa = require('koa'); | ||
var Koa = require('koa'); | ||
var addTrailingSlashes = require('koa-add-trailing-slashes'); | ||
var app = koa(); | ||
var app = new Koa(); | ||
app.use(addTrailingSlashes()); | ||
app.use(function *(){ | ||
app.use(ctx => { | ||
this.body = 'Hello World'; | ||
@@ -41,0 +41,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
5813
8