Show:

Q.Utils Class

Module: Q

Different utilities

Methods

_request

(
  • method
  • uri
  • [data='']
  • [query=null]
  • [user_agent='Mozilla/5.0']
  • [header={}]
  • [callback=null]
)
private

Issues an http request, and returns the response

Parameters:

  • method String

    The http method to use

  • uri String | Array

    The URL to request This can also be an array of [url, ip] to send the request to a particular IP, while retaining the hostname and request URI

  • [data=''] Object | String optional

    The associative array of data to add to query

  • [query=null] Object optional

    The associative array of data to post

  • [user_agent='Mozilla/5.0'] String optional

    The user-agent string to send. Defaults to Mozilla.

  • [header={}] Object optional

    Optional associative array of headers to replace the entire header

  • [callback=null] Function optional

    Callback receives error and result string as arguments

get

(
  • url
  • [data='']
  • [user_agent='Mozilla/5.0']
  • [header={}]
  • [callback=null]
)

Issues a GET request, and returns the response

Parameters:

  • url String | Array

    The URL to get from This can also be an array of [url, ip] to send the request to a particular IP, while retaining the hostname and request URI

  • [data=''] Object | String optional

    The associative array of data or string to add to query

  • [user_agent='Mozilla/5.0'] String optional

    The user-agent string to send. Defaults to Mozilla.

  • [header={}] Object optional

    Optional associative array of headers to replace the entire header

  • [callback=null] Function optional

    Callback receives error and result string as arguments

post

(
  • url
  • [data='']
  • [query=null]
  • [user_agent='Mozilla/5.0']
  • [header={}]
  • [callback=null]
)

Issues a POST request, and returns the response

Parameters:

  • url String | Array

    The URL to post to This can also be an array of [url, ip] to send the request to a particular IP, while retaining the hostname and request URI

  • [data=''] Object | String optional

    The associative array of data or string to add to query

  • [query=null] Array optional

    The associative array of data to post

  • [user_agent='Mozilla/5.0'] String optional

    The user-agent string to send. Defaults to Mozilla.

  • [header={}] Object optional

    Optional associative array of headers to replace the entire header

  • [callback=null] Function optional

    Callback receives error and result string as arguments

preparePath

(
  • filename
  • callback
)

Create folder for filename is it does not exists Folder is created with 'world' access rights with 'Q/internal/umask' config value applied as umask

Parameters:

  • filename String

    The filename

  • callback Function

    Receiver errors if any

queryExternal

(
  • handler
  • [data={}]
  • [url=null]
  • [callback=null]
)

Queries a server externally to the specified handler. Expects json array with either ['slots']['data'] or ['error'] fields filled

Parameters:

  • handler String

    the handler to call

  • [data={}] Array optional

    Associative array of data of the message to send.

  • [url=null] String | Array optional

    and url to query. Default to 'Q/web/appRootUrl' config value

  • [callback=null] Function optional

    Callback receives error and result string as arguments

queryInternal

(
  • handler
  • [data={}]
  • [url=null]
  • [callback=null]
)

Sends a query to Node.js internal server and gets the response This method shall make communications behind firewal

Parameters:

  • handler String

    the handler to call

  • [data={}] Array optional

    Associative array of data of the message to send.

  • [url=null] String | Array optional

    and url to query. Default to 'Q/nodeInternal' config value

  • [callback=null] Function optional

    Callback receives error and result string as arguments

sendToNode

(
  • data
  • [url=null]
)

Sends internal message to Node.js

Parameters:

  • data Array

    Associative array of data of the message to send. It should contain the key "Q/method" so Node can decide what to do with the message.

  • [url=null] String | Array optional

    and url to query. Default to 'Q/nodeInternal' config value and path '/Q/node'

sign

(
  • data
  • fieldKeys
)
Object

Sign data by adding signature field

Parameters:

  • data Object

    The data to sign

  • fieldKeys Array

    Optionally specify the array key path for the signature field

Returns:

signature

(
  • data
  • secret
)
String

Generate signature for an object

Parameters:

Returns:

splitId

(
  • id
  • [lengths=3]
  • [delimiter=path.sep]
  • [internalDelimiter='/']
)
String static

Used to split ids into one or more segments, in order to store millions of files under a directory, without running into limits of various filesystems on the number of files in a directory. Consider using Amazon S3 or another service for uploading files in production.

Parameters:

  • id String

    the id to split

  • [lengths=3] Integer optional

    the lengths of each segment (the last one can be smaller)

  • [delimiter=path.sep] String optional

    the delimiter to put between segments

  • [internalDelimiter='/'] String optional

    the internal delimiter, if it is set then only the last part is split, and instances of internalDelimiter are replaced by delimiter

Returns:

String:

the segments, delimited by the delimiter

validate

()

express server middleware validate signature of internal request