Show HN: Simple express-like routing for front-end
21–28 of 28 posts
Re: Show HN: Simple express-like routing for front-end
#22Re: Show HN: Simple express-like routing for front-end
#23Looks good, but isn't it the as existing https://visionmedia.github.io/page.js/ ?
Re: Show HN: Simple express-like routing for front-end
#24Earlier quoted context omitted.
Ah that is really cool, recently a user requested a feature[1] that is basically this but I solved it in a different way [undocumented]: pagex.base = '/users'; pagex('/', listUsers); pagex('/:username', showUser); pagex.base = ''; I am still considering extend it in this way: pagex.namespace('/users', function(pagex){ pagex('/', listUsers); pagex('/:username', showUser); }); [1] https://github.com/franciscop/pagex/is…
Why .namespace and not .use like express?
Re: Show HN: Simple express-like routing for front-end
#25Earlier quoted context omitted.
I see, but I don't really like this extra functionality for pagex. I am not looking to copy express with middleware for front-end, just wanted some easy and straight way to load a script if we are in the correct part of the website.
Uh, then you and I have very different definitions of "express-like". When I think of express I think of middleware.
Re: Show HN: Simple express-like routing for front-end
#26Honestly one of the worst ShowHN submissions I've ever seen.
Re: Show HN: Simple express-like routing for front-end
#27Earlier quoted context omitted.
It was initially a Regex-only project so it was quite different. Then I added path-to-regex and forgot to check if there was some library out there similar so now they are quite similar. However I can see a couple of important differences: 1. The parameters are passed to the callback in pagex which makes it cleaner: pagex('/users/:id/:frag?', function(id, frag = 'profile'){ ... }); While with page.js you have to retr…
Quick tip, instead of passing true here, having an options object improves readability. As somebody who's never seen it before, the following does the opposite of what I expect: pagex('/users', true, function(){ ... }); But _this_ is more readable—communicates exactly what I need to know, and requires no previous knowledge of the library: pagex('/users', { negate: true }, function(){ ... }); Thanks for sharing your l…
Re: Show HN: Simple express-like routing for front-end
#28I'm watching a movie so I haven't looked too deeply at this, but your regexes aren't safe from ReDoS according to substack's safe-regex [1]. It might be worth finding a non-regex-based way to parse regular expressions in case of some weird routes that could cause exponential-time parsing. [1] https://github.com/substack/safe-regex