lib/cli/init/content/blueprints/person.js
function custom_routes(hapi_server, multicolour) {
    // Joi is an amazing validation library,
    // read me at https://github.com/hapijs/joi/blob/v10.2.2/API.md
    const Joi = require("joi")

    // Set up a simple route that counts examples.
    hapi_server.route({
      method: "GET",
      path: "/example/count",
      config: {
        // Get any auth config from core.
        auth: multicolour.get("server").request("auth_config"),

        // Add tags to appear in the /docs endpoint.
        tags: ["api", "example"],

        // Validate the params.
        validate: {
          // Get valid headers from Multicolour.
          headers: Joi.object(
            multicolour.get("server")
              .request("header_validator")
              .get()
          ).unknown(true)
        },

        // Validate the response.
        response: {
          // Get the schema from Multicolour to validate the response.
          schema: Joi.object({
            count: Joi.number().required(),
            message: Joi.string()
          })
            .meta({className: "person_count"})
            .label("person_count")
        },

        handler: (request, reply) => {
          // `this` is the current model but only with
          // a full function () definition (no fat arrows)
          // on the custom_routes file.
          this.count(request.url.query)
            .then(count => reply({
              count,
              message: "Try POST /person to increase this count result!"
            }))
        }
      }
    })
  }
function custom_routes(hapi_server, multicolour) {
    // Joi is an amazing validation library,
    // read me at https://github.com/hapijs/joi/blob/v10.2.2/API.md
    const Joi = require("joi")

    // Set up a simple route that counts examples.
    hapi_server.route({
      method: "GET",
      path: "/example/count",
      config: {
        // Get any auth config from core.
        auth: multicolour.get("server").request("auth_config"),

        // Add tags to appear in the /docs endpoint.
        tags: ["api", "example"],

        // Validate the params.
        validate: {
          // Get valid headers from Multicolour.
          headers: Joi.object(
            multicolour.get("server")
              .request("header_validator")
              .get()
          ).unknown(true)
        },

        // Validate the response.
        response: {
          // Get the schema from Multicolour to validate the response.
          schema: Joi.object({
            count: Joi.number().required(),
            message: Joi.string()
          })
            .meta({className: "person_count"})
            .label("person_count")
        },

        handler: (request, reply) => {
          // `this` is the current model but only with
          // a full function () definition (no fat arrows)
          // on the custom_routes file.
          this.count(request.url.query)
            .then(count => reply({
              count,
              message: "Try POST /person to increase this count result!"
            }))
        }
      }
    })
  }
function custom_routes ( hapi_server , multicolour ) { // Joi is an amazing validation library, // read me at https://github.com/hapijs/joi/blob/v10.2.2/API.md const Joi = require ( "joi" ) // Set up a simple route that counts examples. hapi_server . route ( { method : "GET" , path : "/example/count" , config : { // Get any auth config from core. auth : multicolour . get ( "server" ) . request ( "auth_config" ) , // Add tags to appear in the /docs endpoint. tags : [ "api" , "example" ] , // Validate the params. validate : { // Get valid headers from Multicolour. headers : Joi . object ( multicolour . get ( "server" ) . request ( "header_validator" ) . get ( ) ) . unknown ( true ) } , // Validate the response. response : { // Get the schema from Multicolour to validate the response. schema : Joi . object ( { count : Joi . number ( ) . required ( ) , message : Joi . string ( ) } ) . meta ( { className : "person_count" } ) . label ( "person_count" ) } , handler : ( request , reply ) => { // `this` is the current model but only with // a full function () definition (no fat arrows) // on the custom_routes file. this . count ( request . url . query ) . then ( count => reply ( { count , message : "Try POST /person to increase this count result!" } ) ) } } } ) }
We can add any custom routes we like by defining them
in the custom_routes function.

There's no magic, no trade offs you simply write the code
you would normally write here.

Multicolour will not modify, read or actually do anything
to your custom code, it's yours and yours only.

@param  {Hapi} hapi_server running your API.
@param  {Multicolour} multicolour instance this REST API is running in.
@return {void}
We can add any custom routes we like by defining them in the custom_routes function .