From 0bdaacb8aa5d83a55b3574ffa89944f4f5cd7da4 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Mon, 15 Oct 2018 21:30:29 -0600 Subject: [PATCH] allow port in remote client --- lib/rc/index.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/rc/index.js b/lib/rc/index.js index acd0dc7..174f130 100644 --- a/lib/rc/index.js +++ b/lib/rc/index.js @@ -79,11 +79,19 @@ module.exports.create = function (state) { url += ('?_body=' + encodeURIComponent(json)); } var method = opts.method || (args && 'POST') || 'GET'; - var req = http.request({ - socketPath: state._ipc.path - , method: method + var reqOpts = { + method: method , path: url - }, function (resp) { + }; + var fs = require('fs'); + var portFile = path.join(path.dirname(state._ipc.path), 'telebit.port'); + if (fs.existsSync(portFile)) { + reqOpts.host = 'localhost'; + reqOpts.port = parseInt(fs.readFileSync(portFile, 'utf8').trim(), 10); + } else { + reqOpts.socketPath = state._ipc.path; + } + var req = http.request(reqOpts, function (resp) { makeResponder(service, resp, fn); });