Skip to content

REST Routers

Patrik Meijer edited this page Jul 26, 2017 · 3 revisions

Custom REST-routers can be added to the webgme server and mounted at a configured path. The module defining the router should return a router instance of Express-Router and in addition provide three functions:

  • initialize called before the modules in middlewareOptions are running
  • start called just before the server is about to start listening and all middlewareOptions modules are running
  • stop called when the server has stopped listening (middlewareOptions are still running at this point).

Boilerplate code for a router can be generated by webgme-cli by using the command:

webgme new router MyCustomRouter

Middleware options

What's specific to webgme regarding routers are the passed "so called" middlewareOptions (passed as middlewareOpts in the boiler plate).

 * @param {object} middlewareOpts - Passed by the webgme server.
 * @param {GmeConfig} middlewareOpts.gmeConfig - GME config parameters.
 * @param {GmeLogger} middlewareOpts.logger - logger
 * @param {function} middlewareOpts.ensureAuthenticated - Ensures the user is authenticated.
 * @param {function} middlewareOpts.getUserId - If authenticated retrieves the userId from the request.
 * @param {object} middlewareOpts.gmeAuth - Authorization module.
 * @param {object} middlewareOpts.safeStorage - Accesses the storage and emits events (PROJECT_CREATED, COMMIT..).
 * @param {object} middlewareOpts.workerManager - Spawns and keeps track of "worker" sub-processes.

Use cases

  • Store and serve access-controlled data outside of the projects (gmeAuth can be used if access is related to projects).
  • Serve other webpages than the single-paged generic UI app.
You can’t perform that action at this time.