koa-rewrite
URL rewrite middleware for koa
Last updated 2 years ago by coderhaoxin .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install koa-rewrite 
SYNC missed versions from official npm registry.

koa-rewrite

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.

Installation

$ npm install koa-rewrite

Examples

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 /foo..bar 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'));

Debugging

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

License

MIT

Current Tags

  • 3.0.1                                ...           latest (2 years ago)
  • 2.1.0                                ...           next (5 years ago)
  • 1.1.2                                ...           v1 (3 years ago)

7 Versions

  • 3.0.1                                ...           2 years ago
  • 3.0.0                                ...           3 years ago
  • 1.1.2                                ...           3 years ago
  • 2.1.0                                ...           5 years ago
  • 1.1.1                                ...           5 years ago
  • 1.1.0                                ...           7 years ago
  • 1.0.0                                ...           7 years ago

Copyright 2014 - 2016 © taobao.org |