arangodbfoxx

Foxx router just doesn't working


I'm currently trying to migrate my code from ArangoDB v2.8 to v3.0.1 and I'm stuck with routes. I have a simple route like:

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

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

and my BASE URL is:

and of course my router is registered in manifest.json as "main": "index.js",

but when I'm trying to access it via /_db/ilearn/api/hello I'm getting 404 "unknown path '/api/hello'".

I have tried changing URL in all possible ways, nothing helps. What am I doing wrong here?

Thanks


Solution

  • Unlike controllers, routers are not mounted automatically. This allows passing them around as exports and nesting them arbitrarily. The "main" file also does not register routers (like the "controllers" files did for controllers) but merely specifies the entry point of your service.

    In order to mount a router you need to use the module.context.use function. You can mount a router on the service's mount point directly by omitting the path and just passing the router: module.context.use(router).