Implemented forwarding of requests to the master

Implement the forwardTo function for requests to the master server.
This commit is contained in:
Hornwitser committed 2020-03-13 22:46:17 +01:00
1 parent 5681ef9733
commit 6a8346186f
3 files changed
+15 -6

No files matched your search

+9 -4
View File
@@ -20,9 +20,9 @@ class Request {
* Links this request is valid on. Takes an array of strings
* containing "<source>-<target>" specifications.
* @param {?string} forwardTo -
* Optional target to forward this request to. Only 'instance' is
* currently supported and adds instance_id into the
* requestProperties.
* Optional target to forward this request to. 'instance' add
* instance_id into the requestProperties and forward to the given
* instance. 'master' forwards it to the master server.
* @param {Object<string, Object>} requestProperties -
* Mapping of property values to JSON schema specifications for the
* properties that are valid in the data payload of this requst.
@@ -46,7 +46,7 @@ class Request {
{"instance_id": { type: "integer" }}, requestProperties
);
} else if (forwardTo !== null) {
} else if (forwardTo !== "master" && forwardTo !== null) {
throw new Error(`Invalid forwardTo value ${forwardTo}`);
}
@@ -99,6 +99,9 @@ class Request {
* If forwardTo was set to 'instance' the `forwardRequestToInstance`
* method on the link is used as the default handler.
*
* If forwardTo was set to 'master' the `forwardRequesToMaster` method
* on the link is used as the default handler.
*
* Does nothing if the link is neither a source nor a target for this
* request.
*
@@ -121,6 +124,8 @@ class Request {
if (!handler) {
if (this.forwardTo === 'instance') {
handler = link.forwardRequestToInstance;
} else if (this.forwardTo === "master") {
handler = link.forwardRequestToMaster;
}
}