1 回复
####example.js
// 路由表
var routes = {
'error' : { // 无效路由
'404' : function (req, res) {
res.end('get 404');
}
},
'127.0.0.1:8800' : {
'=' : { // 精确匹配,优先级最高
'/' : { // '/' '/form' '/product'
get : function (req, res) { // get post put delete
res.end('get /');
}
}
},
'~' : [ // id匹配,优先级次
{
path : '/:id', // '/:id' '/:id/edit' '/:id/blog/:id'
get : function (req, res) {
res.end('get ' + req.ids[0]);
}
}
],
'$' : [ //正则匹配,优先级最低
{
path : /^(?:\/css\/|\/js\/|\/img\/|\/audio\/|\/video\/|\/pipe\/)/, // '/css/a.css' '/js/lib/a.js'
get : function (req, res) {
res.end('get $ ...');
}
}
]
}
};
var server = require('http').createServer();
require('ioconnect')(server, routes, {
"uploadDir" : "/home/lili/tmp",
"multiples" : true,
"keepExtensions" : true,
"maxFieldsSize" : 210241024,
"logger" : 1
});
server.listen(8800);
####run
node example.js