Live data from Hacker News

Show HN: Simple express-like routing for front-end

github.com

21–28 of 28 posts

Re: Show HN: Simple express-like routing for front-end

#24

Earlier 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?

Because it is completely unrelated to express, and even with express that is not really how it works so it'd only cause confusion

Re: Show HN: Simple express-like routing for front-end

#25
post #15

Earlier 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.

In the simple way, express accepts a path (url-like fragment) and executes a callback when it matches the url. THAT is what I meant from express-like, but from this and other comments I can see it wasn't clear at all.

Re: Show HN: Simple express-like routing for front-end

#26

Honestly one of the worst ShowHN submissions I've ever seen.

Could you elaborate further, please? What you don't like and what could be improved? It is a small project and I didn't think it'd make it to the front page but yet here it is, so some people must like it and see something positive.

Re: Show HN: Simple express-like routing for front-end

#27

Earlier 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…

I am totally going to do that, but haven't got around to do it yet. This will also add a bit of flexibility (much needed) about how to pass options.

Re: Show HN: Simple express-like routing for front-end

#28

I'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

Isn't this client-side? So, what could a malicious user DoS other than their own browser? Am I missing something?
Post reply on HN