Git Product home page Git Product logo

node.routes.js's Introduction

node.routes.js

A simple url router.

Two methods are provided:

router.route(request, response, urls)

urls should be an array of arrays in the from:

urls = [
    ['/regex', function(request, response){}]
]

Additionally, if your regex contains capture groups, they will be passed as arguments after request and response to your function. For example:

urls = [
    ['^/media/(.*)$', function(request, response, files){
        /* serve file */
    }]
]

In this case, if the url /media/img/logo.png is fetched, the argument files would be passed to the function as "img/logo.png".

router.include(urls)

urls should be in the same form as for route. This is used for nesting url lookups. That is all /forum/ urls go to forum.urls and so on. For example:

var router = require('./router');
var forumUrls = require('./forum').urls;
var home = require('./pages').home;

urls = [
    ['^/$', home],
    ['^/forum/.*', router.include(forumUrls)]
]

node.routes.js's People

Contributors

xentac avatar

Stargazers

Angus H. avatar Juanan A avatar Charlike Mike Reagent avatar Nikos M. avatar Doug Leonard avatar Michael Nisi avatar  avatar Turbidsoul avatar Shimon Doodkin avatar Patrick Fitzgerald avatar Justin Shoffstall avatar A.J. Cates avatar Val Packett avatar Andrew Johnston avatar Joseph Kim avatar Rafał Pocztarski avatar  avatar Richard Drake avatar Michał Kuklis avatar Aron Jones avatar Josh Hall avatar Fernando Trasviña avatar Adrian Olaru avatar Adomas avatar Aaron Blohowiak avatar C Dorn avatar Sumeet Agarwal avatar Michael Xavier avatar  avatar Scott Shillcock avatar

Watchers

James Cloos avatar

Forkers

xentac ajcates

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.