This note refers to the implementation of controllers in ALICE O2 Bookkeeping
// lib/server/controllers/about.controller.js
const dbInfo = async (request, response) => {
...
}
module.exports = {
dbInfo
}
Export the controller in controllers/index.js
:
// lib/server/controllers/index.js
const AboutController = require('./about.controller')
module.exports = {
AboutController,
...
}
Define a router, ensuring that the controller
field in module.exports
is a callable. Because you imported with the object notation, you can access the exports as fields of AboutController
. See CommonJS require() and module.exports.
// lib/server/routers/about.router.js
const { AboutController } = require('../controllers');
module.exports = {
method: 'get',
path: 'about',
controller: AboutController.dbInfo,
args: { public: true },
};