-
配置路由规则
将路由文件放在routes文件夹里,修改‘Server.js’文件,增加如下代码:

我们这里指明了require('./routes') routes文件夹,require可以文件但是不能文件夹,所以默认回去寻找index.js,此时我们在routes文件夹新建路由文件index.js,代码如下

我们在routes下同时新增文件hello.js,并且注册hello.js路由,hello.js我们实现具体的请求方法,代码如下:

保存并重启node服务
输入地址:http://localhost:8090/ 输出:hello Hapi
输入地址:http://localhost:8090/hello/first-time 输出:Hello, first-time!