Javascript Module Steps
Module Steps
All module steps :
On Validate
/modules/my-module.js
exports.on_validate = function(ctx) {
return {
  result: true, // if result is false, then error is returned to client
  error: {
    "status": 200,
    "headers": {
      "content-type": "application/json"
    },
    "body_json": { // can be also body_bytes, body_base64, body_str
      "error": "..."
    }
  }
}
On request
/modules/my-module.js
exports.on_request = function(ctx) {
return {
  "error": false, // if error is true, then an error is returned to client with the response specified 
  "status": 200,
  "headers": {
    "content-type": "application/json"
  },
  "body_json": { // can be also body_bytes, body_base64, body_str
    "error": "..."
  },
  "otoroshi_request": {...} // the otoroshi_request from the context with modifications if needed and error === false
}
On Backend Call
/modules/my-module.js
exports.on_backend_call = function(ctx) {
return {
  "delegates_call": false, // if true, response is ignored and otoroshi will forward request to the actual backend
  "status": 200,
  "headers": {
    "content-type": "application/json"
  },
  "body_json": { // can be also body_bytes, body_base64, body_str
    "error": "..."
  }
}
On Response
/modules/my-module.js
exports.on_response = function(ctx) {
return {
  "error": false, // if error is true, then an error is returned to client with the response specified 
  "status": 200,
  "headers": {
    "content-type": "application/json"
  },
  "body_json": { // can be also body_bytes, body_base64, body_str
    "error": "..."
  },
  "otoroshi_response": {...} // the otoroshi_response from the context with modifications if needed and error === false
}
On Error
/modules/my-module.js
exports.on_error = function(ctx) {
  return {
    status: 500,
    headers: {
      'Content-Type': 'application/json'
    },
    body_json: { 
      error: ctx.message,
      cause_id : ctx.cause_id,
      attemps: ctx.call_attemps
      }
  }
 }