Giter VIP home page Giter VIP logo

Comments (5)

chrisdavies avatar chrisdavies commented on August 16, 2024

I was thinking of doing this in rlite. I wrote this: https://github.com/chrisdavies/cljs-router

Which has this feature via this syntax: users/*name

Aso, there's another bug w/ rlite that cljs-router doesn't have, which (if I remember right) is that rlite won't match this:

// Given these two registrations:
const route = rlite(notFound, {
  'foo/bar/baz': someHandler,
  'foo/:name/bing': someOtherHandler
});

// This won't match route('foo/bar/bing');

So, I will add rlite to my queue and get these in.

from rlite.

silverwind avatar silverwind commented on August 16, 2024

Sounds good about the * token. I can confirm that bug:

(require('.')(() => console.log('404'), {
  'foo/bar/baz': () => console.log('1'),
  'foo/:name/bing': () => console.log('2'),
}))('foo/bar/bing');

prints 404.

from rlite.

chrisdavies avatar chrisdavies commented on August 16, 2024

Fixed the bug and added wildcard support.

There is a drawback to these changes, which is that they now require recursion where the previous version didn't. It also added around 100 bytes to the min/gzipped size. It seems like a worthwhile trade-off, though.

If you're using this on the server-side, though, it's possible for this library to cause a stack-overflow now, given a long, malicious URL. So, routes should be matched in a try/catch in that case.

from rlite.

silverwind avatar silverwind commented on August 16, 2024

Thanks! I'm using it purely on client side, so I hope I'm safe :)

from rlite.

silverwind avatar silverwind commented on August 16, 2024

Oh, and I think Node.js should not be able to trigger a stack overflow via recursion. There's two limits in place, first is the 80kB maximum HTTP header size:

https://github.com/nodejs/node/blob/master/deps/http_parser/http_parser.h#L64

And secondly, there's v8's maximum call stack limit that depends on stack size, thought tail call optimization might change that:

http://2ality.com/2014/04/call-stack-size.html

from rlite.

Related Issues (20)

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.