@rill/rewrite

1.1.0 • Public • Published

Rill
@rill/rewrite
API stability Standard NPM version Downloads Gitter Chat

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!

Package Sidebar

Install

npm i @rill/rewrite

Weekly Downloads

2

Version

1.1.0

License

MIT

Last publish

Collaborators

  • dylanpiercey