Router is a static HTTP router mapping indexed HTTP patterns to indexed request outputs.
patterns
inport is an addressable parameter accepting patterns the router handles, e.g.:
'get /hello' -> PATTERN[0] Router
'post /world' -> PATTERN[1] Router
filter
inport is an optional parameter accepting custom middleware function applied to all routes in the router.
app
inport accepts an application object and configures it with patterns and filters, mapping inputs and outputs. It's the primary port of the component.
req
is an addressable output sending HTTP request objects to be processed down the stream, e.g.:
Router REQ[0] -> REQ Hello(myapp/HelloController)
Router REQ[1] -> REQ World(myapp/WorldController)
The component is triggered by the app
port, which recieves a value from an upstream component on application start. By the moment app
packet is received, all filter
and pattern
values must have already been received. If using NoFlo "as is", it is all screwed: first app
packet arrived because it is triggered by an IIP in an upstream component, then pattern
IIPs arrive, then filter
arrives from another upstream component. And these events can be mixed in a different order.
For filter
param I'm doing a nifty trick by utilizing component metadata:
AuthFilter FILTER -> FILTER Router(xpress/Router:filter=on)
component.inPorts.add 'filter',
datatype: 'function'
required: metadata and 'filter' of metadata and metadata.filter is 'on'
This makes WirePattern wait for filter
to arrive before processing app
.
But this trick cannot be applied to pattern
, because it is an addressable port of arbitrary size accepting IIPs.
So, the problem is: how to ensure all pattern IIPs arrive before a value on app
inport. And a related problem: how to ensure a specific order of IIPs in a graph.