@rill/rewrite
v1.1.0
Published
URL rewriter for Rill.
Downloads
2
Maintainers
Readme
URL rewrite and modify middleware for Rill.
Installation
npm install @rill/rewrite
Examples
Rewrite using a regular expression.
const app = require('rill')()
// `/i123` to `/items/123`
app.use(rewrite(/^\/i(\w+)/, '/items/$1'))
Rewrite using route parameters, references may be named or numeric.
// `/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.
// `/js/vendor/jquery.js` to `/public/assets/js/vendor/jquery.js`
app.use(rewrite('/js/*', '/public/assets/js/$1'))
Contributions
- Use
npm test
to run tests.
Please feel free to create a PR!