【发布时间】:2021-05-24 10:31:37
【问题描述】:
我正在使用这个简单的服务器程序
const Hapi = require('hapi');
const server = new Hapi.Server({
host: 'localhost',
port: 8080,
});
server.route({
path: '/',
method: 'GET',
handler: (request, response) => {
response(true);
},
});
server.start(() => {
console.log('Server running at:', server.info.uri);
});
这在服务器启动时给了我以下错误
throw new Error(msgs.join(' ') || 'Unknown error');
^
Error: Invalid server options {
"port" [2]: 8080,
"host" [1]: "localhost"
}
[1] "host" is not allowed
[2] "port" is not allowed
at Object.exports.assert (/Users/aakashverma/Documents/exercises/makeithapi/node_modules/hoek/lib/index.js:736:11)
at Object.exports.apply (/Users/aakashverma/Documents/exercises/makeithapi/node_modules/hapi/lib/schema.js:17:10)
at new module.exports.internals.Server (/Users/aakashverma/Documents/exercises/makeithapi/node_modules/hapi/lib/server.js:32:22)
at Object.<anonymous> (/Users/aakashverma/Documents/exercises/makeithapi/serveEm/serveEm.js:3:16)
at Module._compile (module.js:660:30)
at Object.Module._extensions..js (module.js:671:10)
at Module.load (module.js:573:32)
at tryModuleLoad (module.js:513:12)
at Function.Module._load (module.js:505:3)
at Function.Module.runMain (module.js:701:10)
而我的package.json 的依赖项是这样设置的
"dependencies": {
"axios": "^0.17.1",
"hapi": "^16.6.2"
}
我尝试到处搜索这个问题并找到了一个确切的here,但版本太旧无法比较。
我该如何解决这个问题?
【问题讨论】:
标签: javascript node.js hapijs