Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Does node.js provide a way to write non-trivial clean URLs?

Does node.js provide a way to write non-trivial clean URLs?

Problem

I would like to Write non-trivial dynamic clean Urls in node.js. For example

mynodeserver.com/browse/itemid 

instead of

mynodeserver.com/browse?id=itemid

Right now my static clean urls (browse,login,register,etc) are based on string comparison, which obviously is not the complete solution for this problem.

var pathname = url.parse(request.url).pathname;
//check if there is a request handler for this path
if (typeof handle[ pathname ] === 'function') 
{
    handle[pathname]( response, request, postData );
} 

Is there a native way (or light plugin) to write non-trivial clean URLs?

I'm using Cloud9 IDE

Problem courtesy of: supertopi

Solution

Writing your own parser for urls should not be a difficult job I think. Assuming you know how to use regular expressions.

I've never heard about standalone plugin for doing this, but you can use very good Express framework. It has url parser built-in.

Solution courtesy of: freakish

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

Does node.js provide a way to write non-trivial clean URLs?

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×