Module stick/helpers
A collection of helper functions that makes working with Stick middleware easier.
Functions
- linkTo(app, bindings, text)
- redirectTo(app, bindings)
- resolveApp(app)
- urlFor(app, bindings)
linkTo (app, bindings, text)
Return a link to an action configured using the route
middleware.
The link's URL is generated from the bindings argument as described for the urlFor helper.
Parameters
object|string | app | the application to link to |
object | bindings | an object containing the bindings for the target URL. |
string | text | the link text. |
redirectTo (app, bindings)
Create a response that redirects the client to a different URL.
Parameters
string|object | app | either the URL as string or an app to be passed to `urlFor` |
bindings | bindings | to pass to `urlFor` if first argument is an app. |
Returns
object | a JSGI response that will redirect the client to the specified target |
urlFor (app, bindings)
Return a URL for an action configured using the mount
and route
middlewares.
The app
argument specifies the Stick application to link to, either as reference
to the app itself or as module id of a module exporting the app as app
.
The bindings
argument contains information needed to determine the target
action within that application. Properties in the bindings argument are interpreted
as follows:
The
action
property, if present, identifies the name of the action to link to. Action names are determined from the path arguments provided to theroute
middleware by removing all placeholders and the leading slash. For example, the name for an action routed with/edit/:id
is "edit".Properties in the bindings object that have a placeholder with the same name in the target route are used to provide the value for this placeholder. For example, to URI path to an action in application
app
routed with "/edit/:id" with id5
can be generated as follows:urlFor(app, {action: "edit", id: 5})
All other properties in the bindings object are set as query parameters in the generated URL. For example, if "index" is a route with no placeholders then calling
urlFor("index", {do: "search"})
will generate the URL "/?do=search".
Note that the values for the current request are used as default values for action
and route placehoders, so if you want to use to a different action or placeholder value
you need to make that explicit.
Parameters
object|string | app | the application to link to |
object | bindings | an object containing the bindings for the target URL. |