node.js - 在 Hapi 我得到 h.file is not a function
问题描述
我正在运行最新版本的 hapi,但是当我尝试服务器静态文件时,我收到错误 h.file is not a function。我已经安装了惰性。这是相关代码和我的 package.json
包.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 中注册惰性对象 await server.register(require('inert'));
推荐阅读
- chromium - 主框架的 document.querySelector
- prestashop-1.7 - Prestashop 1.7 覆盖默认的 presta 模块源文件
- sql - 这个 SQL 连接有什么作用?
- python - 未找到“books_recsys_app.views.home”的 NoReverseMatch 异常值反转
- azure-cosmosdb - 与 CosmosDb 中的 order by 不同
- python - 在子类定义期间重新初始化父类属性
- microsoft-graph-api - MS Graph API 拒绝令牌
- kubernetes - 502 带有 Kubernetes 入口的错误网关
- scala - 如何检查哪些隐含是模棱两可的?
- javascript - 在子组件中输入 useState setter