Module: util/middleware

Express middleware functions to inject into the HTTP processing

Source:

Methods

(inner) createImposterValidator(imposters) → {function}

Returns a middleware function to return a 404 if the imposter does not exist

Parameters:
Name Type Description
imposters Object

The imposters repository

Source:
Returns:
Type
function

(inner) defaultIEtoHTML(request, response, next)

The mountebank server uses header-based content negotiation to return either HTML or JSON
for each URL. This breaks down on IE browsers as they fail to send the correct Accept header,
and since we default to JSON (to make the API easier to use), that leads to a poor experience
for IE users. We special case IE to html by inspecting the user agent, making sure not to
interfere with XHR requests that do add the Accept header

Parameters:
Name Type Description
request Object

The http request

response Object

The http response

next function

The next middleware function to call

Source:

(inner) globals(vars) → {function}

Returns a middleware function that passes global variables to all render calls without
having to pass them explicitly

Parameters:
Name Type Description
vars Object

the global variables to pass

Source:
Returns:
Type
function

(inner) json(log) → {function}

Returns a middleware function that defaults the content type to JSON if not set to make
command line testing easier (e.g. you don't have to set the Accept header with curl) and
parses the JSON before reaching a controller, handling errors gracefully.

Parameters:
Name Type Description
log Object

The logger

Source:
Returns:
Type
function

(inner) logger(log, format) → {function}

Returns a middleware function that logs the requests made to the server

Parameters:
Name Type Description
log Object

The logger

format string

The log format

Source:
Returns:
Type
function

(inner) useAbsoluteUrls(port) → {function}

Returns a middleware function to transforms all outgoing relative links in the response body
to absolute URLs, incorporating the current host name and port

Parameters:
Name Type Description
port number

The port of the current instance

Source:
Returns:
Type
function