Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript hapi中的server.register错误_Javascript_Hapijs - Fatal编程技术网

Javascript hapi中的server.register错误

Javascript hapi中的server.register错误,javascript,hapijs,Javascript,Hapijs,我在为我的新项目学习hapijs。我被server.register()方法卡住了。我相信我做的一切都是对的,但我却犯了一个错误,“无法读取未定义的属性‘寄存器’”。请帮忙。先发制人 const hapi=require('hapi'); const server=new hapi.Server(); //Add connection server.connection({ port:4500, host:'localhost' }); //creating rout

我在为我的新项目学习hapijs。我被server.register()方法卡住了。我相信我做的一切都是对的,但我却犯了一个错误,“无法读取未定义的属性‘寄存器’”。请帮忙。先发制人

    const hapi=require('hapi');
const server=new hapi.Server();

//Add connection
server.connection({
    port:4500,
    host:'localhost'
});

//creating route

server.route({
    method:'GET',
    path:'/',
    handler:(req,reply)=>{
        reply('Succ`enter code here`essfully created first route');
    }
});

//dynamic route
server.route({
    method:'GET',
    path:'/user/{id}',
    handler:(req,reply)=>{
        reply(`<p>User : ${req.params.id}</p>`)
    }
})

//static route

server.register(require('inert'),(err)=>{
    if(err)throw err;
    server.route({
        method:'GET',
        path:'/about',
        handler:(req,reply)=>{
            reply.file('./public/index.html')
        }
    })
})

//Start connection
server.start().then(
    ()=>console.log(`Server is running at ${server.info.uri}`)
).catch(
    err=>{throw err} 
)
const hapi=require('hapi');
const server=new hapi.server();
//添加连接
服务器连接({
港口:4500,
主机:'localhost'
});
//创建路由
服务器路由({
方法:'GET',
路径:“/”,
处理程序:(请求,回复)=>{
回复('success`在此处输入代码`成功创建第一条路线');
}
});
//动态路径
服务器路由({
方法:'GET',
路径:'/user/{id}',
处理程序:(请求,回复)=>{
回复(`User:${req.params.id}

`) } }) //静态路由 server.register(需要('indirect'),(err)=>{ 如果(错误)抛出错误; 服务器路由({ 方法:'GET', 路径:'/about', 处理程序:(请求,回复)=>{ reply.file(“./public/index.html”) } }) }) //启动连接 server.start()。然后( ()=>console.log(`Server正在${Server.info.uri}`上运行) ).接住( err=>{throw err} )
这可能是插件和hapi版本不兼容的问题。尝试使用以下版本,它会很好地工作

"hapi": "^16.6.2",
"inert": "^4.2.1",

你能告诉我你的版本吗?