GithubHelp home page GithubHelp logo

berryk / express-urlrewrite Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kapouer/express-urlrewrite

0.0 1.0 0.0 5 KB

URL rewriting middleware for express

License: Other

JavaScript 100.00%

express-urlrewrite's Introduction

express-urlrewrite

URL rewrite middleware for express.

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'));

In the above examples, the original query string (if any) is left untouched. The regular expression is applied to the full url, so the query string can be modified as well:

app.use(rewrite('/file\\?param=:param', '/file/:param'))

The query string delimiter (?) must be escaped for the regular expression to work.

New in version 1.1

app.use(rewrite('/path', '/anotherpath?param=some'))

now updates req.query, so req.query.param == 'some'.

New in version 1.2

rewrite can be used as a route middleware as in

app.get('/route/:var', rewrite('/rewritten/:var'));

app.get('/rewritten/:var', someMw);

Instead of passing control to next middleware, it passes control to next route.

Debugging

Set environment variable DEBUG=express-urlrewrite

express-urlrewrite's People

Contributors

kapouer avatar paulogr avatar

Watchers

Keith Berry avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.