robohydra Class
Utility functions.
Item Index
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
ObjectServer configuration
-
plugins
ArrayList 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) andconfig
(object with configuration variables for the plugin). -
summoner
ObjectSummoner 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
ArrayArray with extra directories to search for RoboHydra plugins.
-
secure
BooleanWhether the RoboHydra server should use HTTPS or not.
-
sslOptions
ObjectSSL options. Only used if
config.secure
is truthy.-
key
StringThe path to the secret key file for the SSL certificate. -
cert
StringThe path to the certificate file for the SSL certificate.
-
-
getParsingParams
Simplifies the interface for getting a clean content-type & charset header value.
-
headerValue
Parameters:
-
headerValue
StringA header value to clean.
Returns:
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
Parameters:
-
buff
BufferThe initial buffer value to parse.
-
headers
ObjectUsed to select the conversion strategy.
Returns:
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
RequestThe request object to proxy.
-
res
ResponseThe response object to write the result to.
-
proxyTo
URLThe URL to proxy to, either in the form of a URL object (result of the url.parse method) or a string.
-
opts
Object-
httpRequestFunction
FunctionThe http.request function or a mock of it.
-
httpsRequestFunction
FunctionThe https.request function or a mock of it.
-
setHostHeader
BooleanSpecifies 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
StringThe full path of the file to be served.
-
res
ResponseResponse object to write the response to.
-
opts
Object-
fs
ObjectThe 'fs' module (or a mock) to be used when reading from the filesystem.
-
mime
ObjectThe 'mime' module (or a mock) to be used when figuring out the MIME type for a file.
-
headers
ObjectAn object with the incoming request headers (for caching and such).
-
indexFiles
ArrayAn 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").
-