Node.js开源应用框架HapiJS介绍(2)

server.route({
method: 'GET',
path: '/{name}',
handler: function(request, reply){
reply('Hello, ' + encodeURIComponent(request.params.name) + "!");
}
});

server.pack.register(Good, function(err){
if(err){
// something bad happened loading the plugin
throw err;
}
server.start(function(){
server.log('info', 'Server running at: ' + server.info.uri);
});
});


运行server.js,控制台输出:

复制代码 代码如下:


141102/161007.644, info, Server running at: :3000


如果我们接着访问::3000/liqiang
和:3000/
控制台会继续输出:

复制代码 代码如下:


141102/161150.689, request, :3000: get /liqiang {} 200 (37ms)
141102/161155.812, request, :3000: get / {} 200 (4ms)

您可能感兴趣的文章:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wgxzgy.html