Router

ROUTER is a store of routes/events (WebSockets)/schema's (GraphQL) and middlewares. You can add list of routes to your module config as:

"routes": {
    "users_get": { "path": "users", "method": "get" },
}

where

  • users_getis name of route that will use for calling ACTIONS event
  • "path": "users"is a url that will use for send request to API.
  • "method": "get"is a API request method (get, post, update, delete).

For adding routes to Router you need to import key "routes" from module config to module "index.js" file.

const { routes } = require('./config.json');

ROUTER.set('routes', routes);

Also you need to convert config key to event form (with dot instead underscore) for use key as event in ACTIONS.

const { users_get } = utils.convertkeysToDots(routes); // now users_get is a string 'users.get'

ACTIONS.on(users_get, () => {});

As you can see - ROUTER has method set which add routes to main routes list. If you wanna see global list of routes - you can call other method get:

ROUTER.get('routes');

Also this works for other entities: events, schema's and middlewares.


results matching ""

    No results matching ""