gpt4 book ai didi

node.js - 在 Hapi 中我得到 h.file is not a function

转载 作者:太空宇宙 更新时间:2023-11-03 22:58:34 25 4
gpt4 key购买 nike

我正在运行最新版本的 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")
}
})

最佳答案

忘记在hapi中注册惰性对象等待 server.register(require('inert'));

关于node.js - 在 Hapi 中我得到 h.file is not a function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53693311/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com