首页 文章

在Hapi我得到h.file不是一个函数

提问于
浏览
0

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

1 回答

  • 0

    忘了在hapi中注册惰性对象await server.register(require('inert'));

相关问题