API Docs for: HEAD
Show:

robohydra Class

Utility functions.

Methods

createRoboHydraServer

(
  • config
)

Creates a RoboHydra server, similar to http.createServer or https.createServer. The returned object is in fact the same as with the createServer, so the same methods (listen, on, etc.) can be used.

Parameters:

  • config Object

    Server configuration

    • plugins Array

      List of plugins to load: each element in the array must be either a string (name of the plugin to load) or an object with the keys name (string with the plugin name) and config (object with configuration variables for the plugin).

    • summoner Object

      Summoner configuration. Right now the only valid key is hydraPickerPlugin, the name of the plugin containing the hydra picker to use (useful in case there are several).

    • pluginLoadPaths Array

      Array with extra directories to search for RoboHydra plugins.

    • secure Boolean

      Whether the RoboHydra server should use HTTPS or not.

    • sslOptions Object

      SSL options. Only used if config.secure is truthy.

      • key String
        The path to the secret key file for the SSL certificate.
      • cert String
        The path to the certificate file for the SSL certificate.

getParsingParams Simplifies the interface for getting a clean content-type & charset header value.

(
  • headerValue
)
Object | Undefined

Parameters:

  • headerValue String

    A header value to clean.

Returns:

Object | Undefined:

A clean representation of the input value, or undefined

parse Parses the a buffer into the expected internal type, based on standard request headers (content-type and charset).

(
  • buff
  • headers
)
Object

Parameters:

  • buff Buffer

    The initial buffer value to parse.

  • headers Object

    Used to select the conversion strategy.

Returns:

Object:

Parsed post-body according to content-type and charset.

proxyRequest

(
  • req
  • res
  • proxyTo
  • opts
)

Proxies the given request to the given URL, writing the result in the given response object.

Parameters:

  • req Request

    The request object to proxy.

  • res Response

    The response object to write the result to.

  • proxyTo URL

    The URL to proxy to, either in the form of a URL object (result of the url.parse method) or a string.

  • opts Object
    • httpRequestFunction Function

      The http.request function or a mock of it.

    • httpsRequestFunction Function

      The https.request function or a mock of it.

    • setHostHeader Boolean

      Specifies if the "Host" header should be set in the proxied request, so pretend as if the original request was indeed intended for the final URL. Defaults to false.

serveStaticFile

(
  • filePath
  • res
  • opts
)

Serves a static file with correct headers and such, writing the result in the given response object.

Parameters:

  • filePath String

    The full path of the file to be served.

  • res Response

    Response object to write the response to.

  • opts Object
    • fs Object

      The 'fs' module (or a mock) to be used when reading from the filesystem.

    • mime Object

      The 'mime' module (or a mock) to be used when figuring out the MIME type for a file.

    • headers Object

      An object with the incoming request headers (for caching and such).

    • indexFiles Array

      An array with the filenames to be used as index if the given file path is a directory (by default, "index.html", "index.htm", "home.html" and "home.htm").