Koa middleware that converts path to lowercase if not already.
Notice: koa-lowercase-path@2 supports koa@2; if you want to use this module with koa@1, please use koa-lowercase-path@1.
npm install koa-lowercase-path
const Koa = require('koa');
const app = new Koa();
app.use(require('koa-lowercase-path')(opts));
opts
options object.
defer
- If true, serves after yield next, allowing any downstream middleware to respond first.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 lowercasePath = require('koa-lowercase-path');
const app = koa();
app.use(lowercasePath());
app.use(ctx => {
ctx.body = 'Hello World';
});
app.listen(3000);
Make sure this is added before an eventual koa-static middleware to make sure requests to files are not changed and managed correctly. This because it will not rewrite the URL if a body
has been set along with status 200
.
If all paths always should be rewritten one can set defer
to false
.
MIT