API

Boostack Routing 🚆

Boostack manages your routes in separate files from index.js.

We define all routes in a route.js file and reference it from my index.js. This will keep the code separated and easier to manage.

Boostack manage also your logic in separate files named "controllers"

This is a simple example that says "Hi I am the invitation controller"

//invitation-controller.js
...
module.exports.invitationState = function(req, res) {

    return res.status(200).json({ message: "Hi I am the invitation controller" });
};
...

Each controller file has its route file for the example below "invitation-routes" where we define our controllers.

//invitation-routes.js
...
router.get("/checkstate/:token", controller.invitationState);
...

module.exports = router;

The routes file includes all the routes that we can manage easily.

Now you can define your prefix in a more automated/configurable way like so

//routes.js
...
const invitationRoutes = require("./api/invitation/invitation-routes");
...
function registerRoutes(app) {
...
  app.use("/api", invitationRoutes);
...
}

Back in the index.js we add a single line to require this new library and that’s it!

//index.js

const { registerRoutes } = require("./routes");
registerRoutes(app);

Last updated

Was this helpful?