Skip to content

Instrumentation

Eugene Lazutkin edited this page May 24, 2016 · 2 revisions

Bundler can be instrumented using following parameters:

  • Security-related properties. Be careful, while implementing them, because they are critical for securing a bundler's endpoint!
    • isUrlAcceptable(url) — a function, which takes a URL string, and return a falsy value for rejected URLs, and a truthy value otherwise. It is a required property. Default: none.
    • resolveUrl(url) — a function, which takes a URL string, and returns a potentially transformed URL. It can be used to rewrite and redirect URLs. Default: the identity function, which returns its argument unchanged.
    • maxRequests — a positive integer number, which specifies the maximal size of an acceptable bundle. To prevent a denial-of-service attack, and reduce a potential for amplification of I/O requests, set it to a reasonable number. Default: 20.
    • setHeaders(results, res) — takes an array of result objects returned by request, or error objects, and a bundle result object. Its return value is ignored. The procedure may set headers on the result object, or modify it in any other way. Note: the content type header will be overridden with 'application/json'. Default: nothing.
  • Data-processing function properties.
    • processResult(data, req) — takes a created data object (described in the protocol), and an original bundle request object, returns a data object, which is used as a result for an individual data request. Default: the identity function.
    • processFailure(data, req) — the difference with processRequest() is it's called in the case of failure, and a data object is formed to reflect it. Default: the identity function.
    • processBundle(data, req) — just like processResult(), but it takes a bundle result as a data object.
      The bundle format is described in the protocol. Default: the identity function.
  • Event-related function properties. They are all optional procedures, which return nothing.
    • onBundleStart(req) — takes an original bundle request object. It is called, when a bundle is accepted for processing before any other code. Default: nothing.
    • onBundleFinish(req) — takes an original bundle request object. It is called, when a bundle is about to be sent back. Default: nothing.
    • onItemStart(req, options, index, payload) — takes an original bundle object, a current options object (described in the protocol), an index in a bundle, and an array of bundled options objects. It is called before processing an individual bundled I/O request. Default: nothing.
    • onItemFinish(req, value, index, payload) — takes an original bundle object, a received response, or an error, an index in a bundle, and an array of bundled options objects. It is called after a response was received for that I/O request (either an error or a valid data). Default: nothing.

Clone this wiki locally