Foxx 路由器无法正常工作

Foxx router just doesn't working

我目前正在尝试将我的代码从 ArangoDB v2.8 迁移到 v3.0.1,但我遇到了路由问题。我有一条简单的路线,例如:

const router = require('@arangodb/foxx/router')()

router.get('/hello', function (req, res) {
  res.json({ hi: 'world' })
})

我的 BASE URL 是:

当然我的路由器在 manifest.json 中注册为 "main": "index.js",

但是当我尝试通过 /_db/ilearn/api/hello 访问它时,我得到 404 "unknown path '/api/hello'"

我已尝试以所有可能的方式更改 URL,但无济于事。我在这里做错了什么?

谢谢

与控制器不同,路由器不会自动安装。这允许将它们作为导出传递并任意嵌套。 "main" 文件也不注册路由器(就像 "controllers" 文件注册控制器一样),而只是指定服务的入口点。

为了安装路由器,您需要使用 module.context.use 函数。您可以通过省略路径并仅传递路由器来直接在服务的挂载点上挂载路由器:module.context.use(router).

如果您还没有看过,我还建议您查看迁移指南,其中涵盖了您在从 2.x 迁移到 3.0 时可能遇到的其他 "gotchas":https://docs.arangodb.com/3.0/Manual/Foxx/Migrating2x/index.html

关于迁移控制器的章节中特别提到了这个陷阱:https://docs.arangodb.com/3.0/Manual/Foxx/Migrating2x/Controllers/index.html