Donnovan
Donnovan

Reputation: 223

change options object on request

Is it possible to change a options object in a request, this doesn't seem to work for me. Can someone help me with this? i am trying to use one request to 2 different urls.

    var options = { url: "http://" + lane.address + "/awp/SSLDiagnostics/diagnostics.htm", timeout: interval };

if (lane.filter === "vf0")options = {url: "http://" + lane.address + "/awp/IOTest/SSLDiagnostics/diagnostics.htm", timeout: interval };

and use it like this

request(options, function (error, response, body)
{
    if (!error && response.statusCode == 200) {
        var state;
        var cleaned = body.replace(/&#x2[0|7];|'/g, "");
        state = !("vf1" === lane.filter) ? parse_responseOnexs(cleaned) : state = "vf0" === lane.filter ? parse_responseVf0(cleaned) : parse_responseVf1(cleaned);
        if (state) {
            state_update = new lane_state(lane, '', state);
        }
        else {
            state_update = new lane_state(lane, 'Error parsing response from PLC...: ' + body, {});
        }
    }
    else {
        state_update = new lane_state(lane, 'Server is unable to connect to the PLC: ' + error, {});
        failedCount = previousFailedCount + 1;
    }
    if (failedCount != 1) {
        result_callback(state_update);
    }
    setTimeout(function () {
        poll_lanestate(lane, interval, result_callback, failedCount);
    }, interval);
});

Upvotes: 0

Views: 36

Answers (1)

Molkan
Molkan

Reputation: 554

You can just change the 'url' property of the object

options.url = "http://" + lane.address + "/awp/IOTest/SSLDiagnostics/diagnostics.htm";

Upvotes: 2

Related Questions