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.
npm install koa-normalize-path
const Koa = require('koa');
const app = new Koa();
app.use(require('koa-normalize-path')(opts));
opts
options object.
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
.
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);
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. koajs/send#51
MIT