0

我想在 node.js 中编写重要的动态干净 URL。例如

mynodeserver.com/browse/itemid 

代替

mynodeserver.com/browse?id=itemid

现在我的静态干净 url(浏览、登录、注册等)是基于字符串比较的,这显然不是这个问题的完整解决方案。

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 );
} 

是否有本地方式(或轻量级插件)来编写非平凡的干净 URL?

我正在使用 Cloud9 IDE

4

1 回答 1

2

我认为为 url 编写自己的解析器应该不是一项艰巨的工作。假设您知道如何使用正则表达式。

我从来没有听说过这样做的独立插件,但你可以使用非常好的Express 框架。它内置了 url 解析器。

于 2012-03-13T07:56:40.183 回答