Coder Social home page Coder Social logo

routington's People

Contributors

jonathanong avatar markchadwick avatar yoshuawuyts avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

routington's Issues

How to remove a route ?

Hi Is there a way to remove a defined route ?
I am creating a dynamic router based on top of routington, and as a way I need to add and remove routes. Is there a way to do this in routington ?

Fallback to regex?

@jonathanong is there a way to detect the router finished without fining a match?

I want to be able to run a regex on the path from root level only after the router didn't already find a match.

Parse Method Usage

Can we get an example on how the parse method can be used?

I can seem to find anywhere it is explicitly used.

Thanks

archive this repo?

@jonathanong you have been identified as the last / most active committer in this repo which is inactive for a while. This ping is to check with you to determine:

  • whether do you have any specific maintenance plans with this repo
  • are you fine for this repo to be archived
  • do you believe if there is another stake holder / affected party who should know

thanks

Support .* for routes

Currently /path/:restofroute(.*) - does not match /path/abc/def/ghi/jkl/mnop
Is this not supported, or is there an alternate way of doing this?

How to match a Query String

I have the following snippet and trying to patch a simple query string but for some reason it's not able to match it.

import routington from "routington";

class Router {
  #router: routington
  constructor() {
    this.#router = routington();
  }

  get(path: string, method: string, ...cb: Array<Function>) {
    const node = this.#router.define(path)[0];
    node[method] = node[method] || []
    node[method].push(...cb)
  }

  post(path: string, method: string, ...cb: Array<Function>) {
    const node = this.#router.define(path)[0];
    node[method] = node[method] || []
    node[method].push(...cb)
  }

  match(path: string) {
    return this.#router.match(path);
  }
}

const router = new Router();

router.get('/name', 'GET', function (ctx: object, next: Function) { console.log('middleware') }, function (ctx: object) { console.log('handler') });
router.post('/name', 'POST', function (ctx: object) { console.log('handler2') });



// dispatch
function dispatcher(request: { path: string; method: string }): { param: string; handler: Function } | string | never {
  const match = router.match(request.path);
  if (!match) { console.log('404 - Not Found'); return "" };

  const node = match.node;
  const cb = node[request.method]

  return {
    param: match.param,
    handler: cb
  }
}

console.log(dispatcher({ path: '/name?age=50', method: 'GET' }));

Please assist.

Thanks

Add optional 'tag'

When implementing an event based system it might be very helpful to know which rule matched, so we need a tag.

router.define('/page/:id(\\w{3,30})', { tag: 'page' })
router.define('/user/:id(\\w{3,30})', { tag: 'user' })

var match = router.match('/page/taylorswift')
console.log(match.tag); // output 'page'

Allow Wildcard path

Currently I cannot register a wildcard in routington.

Example

router.define('*');

Or

router.define('/*');

Any help will be appreciated.

After defining several routes, how to know which route it has matched against ?

Hi,

Consider this example:

const routington = require("routington")

const router = routington();

router.define("/");
router.define("/name/:id");
router.define("name/:id/create");

var match = router.match("/name/anurag");
console.log(match);

How do I know against which route to the match object is created.
That is if there is a match, I wanted to know match.pattern should give me :
/name/:id

Is it possible currently, or can this feature be added.
In my code I have to define some rules on pattern, but I want the url pattern which has allowed this match, so those rules can be applied to the request before processing.

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.