on_HTTP_request
converts all requests to the router into Alchemy Service or ResourceService messages
First the http_request
packet is created from the express request
If the request has service
attached (either from additional or resource_path_mw
middleware)
it sends the message directly to the service, otherwise sends it to the resource.
The message is sent then:
- if the message is successful the response to the caller is the content
- if a
MessageNotDeliveredError
is caught then the response to the caller is 404 Bam.not_found
- if a
TimeoutError
is caught then the response to the caller is 408 Bam.timeout_error
on_HTTP_request: (req, res) =>
http_request = {
session_id: req.get 'X-Session-ID'
scheme: req.protocol
host: req.hostname
port: req.port || 80
path: req.path
query: req.query
verb: req.method
headers: req.headers
body: req.body
}
if req.service
send_message = @router_service.send_message_to_service( req.service, http_request )
else
send_message = @router_service.send_message_to_resource( http_request )
send_message
.then( (content) =>
Router.send_HTTP_response(content, res)
)
.catch(MessageNotDeliveredError, =>
Router.send_HTTP_response(Bam.not_found({}, http_request.path), res)
)
.catch(TimeoutError, =>
Router.send_HTTP_response(Bam.timeout_error({}, @options.timeout), res)
)