var http = require('http');
http.createServer(
function (req, res) {
var url = req.url;
var regStr = /^\/([a-zA-Z]+)\/(\d+)$/;
if (regStr.test(url)) {
var level1 = RegExp.$1;
var level2 = RegExp.$2;
res.writeHead(200, { 'content-type': 'text/html;charset=utf-8' });
res.end('一级路由是:' + level1 + ',二级路由是:' + level2);
} else {
res.writeHead(404, { 'content-type': 'text/html;charset=utf-8' })
res.end('404了哟!没有找到正确的请求!');
}
}
).listen(3000, '127.0.0.1');