我正在运行最新版本的hapi,但是当我尝试处理静态文件时,出现错误h.file不是函数。我已经安装了惰性程序。这是相关的代码和我的package.json
package.json
{
"name": "node",
"version": "1.0.0",
"description": "",
"main": "import_data.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"ag-grid-angular": "^19.1.2",
"ag-grid-community": "^19.1.4",
"hapi": "^17.8.1",
"inert": "^5.1.2",
"npm": "^6.4.1",
"sqlite3": "^4.0.4"
}
}
路线代码
// Create a server with a host and port
const server=Hapi.server({
host:'localhost',
port:8000,
routes: {
files: {
relativeTo: Path.join(__dirname, 'mibfiles')
}
}
});
server.route({
method: 'GET',
path: '/mibfiles/{mibname}',
handler: function(request, h) {
return h.file('mibfiles/' + request.params.mibname + ".mib")
}
})
答案 0 :(得分:1)
忘记在hapi中注册惰性对象 等待server.register(require('inert'));