Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including koa-rewrite-75lb with all npm packages installed. Try it out:

var koaRewrite75lb = require("koa-rewrite-75lb")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

koa-rewrite-75lb v3.0.1

URL rewrite middleware for koa


URL rewrite middleware for koa.

Notice: koa-rewrite@2+ supports koa@2, if you want to use this module with koa@1, please use koa-rewrite@1.


$ npm install koa-rewrite


Rewrite using a regular expression, rewriting /i123 to /items/123.

app.use(rewrite(/^\/i(\w+)/, '/items/$1'));

Rewrite using route parameters, references may be named or numeric. For example rewrite / to /commits/foo/to/bar:

app.use(rewrite('/:src..:dst', '/commits/$1/to/$2'));
app.use(rewrite('/:src..:dst', '/commits/:src/to/:dst'));

You may also use the wildcard * to soak up several segments, for example /js/vendor/jquery.js would become /public/assets/js/vendor/jquery.js:

app.use(rewrite('/js/(.*)', '/public/assets/js/$1'));


Use the DEBUG environment variable with "koa-rewrite":

koa-rewrite rewrite /i123 -> /items/123 +762ms
koa-rewrite rewrite /i321 -> /items/321 +9s
koa-rewrite rewrite /i123 -> /items/123 +5s




RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free