koa-normalize-path
v2.0.0
Published
Koa middleware that normalizes paths
Downloads
166
Readme
koa-normalize-path
Koa middleware that normalizes paths.
Notice: koa-normalize-path@2 supports koa@2; if you want to use this module with koa@1, please use koa-normalize-path@1.
Installation
npm install koa-normalize-path
API
const Koa = require('koa');
const app = new Koa();
app.use(require('koa-normalize-path')(opts));
opts
options object.
Options
defer
- If true, serves after yield next, allowing any downstream middleware to respond first. Defaults totrue
.chained
- If the middleware should continue modifying the url if it detects that a redirect already have been performed. Defaults totrue
.
Example
const Koa = require('koa');
const normalizePath = require('koa-normalize-path');
const app = new Koa();
app.use(normalizePath());
app.use(ctx => {
ctx.body = 'Hello World';
});
app.listen(3000);
Important
When used together with koa-static it might be a good idea to set defer
to true
for koa-static
and false for koa-normalize-path
. This to avoid a potential problem that will result in an error being thrown stating the path is malicious if it starts with multiple slashes. https://github.com/koajs/send/issues/51
License
MIT