diff --git a/index.js b/index.js index 2757d36..db32d32 100644 --- a/index.js +++ b/index.js @@ -2,6 +2,7 @@ var net = require('net'); var http = require('http'); var fs = require('fs'); var winston = require("winston"); +var rp = require("request-promise"); // Rudimentary logger. // TODO - Make this filename configurable. @@ -40,8 +41,13 @@ class HttpRequest { * * TODO - Implement me. */ - async forwardRequest() { - + forwardRequest(callbackFn) { + console.log("Forwarding.") + http.request({ + host: this.attrs.headers.Host, + method: this.attrs.Method, + headers: this.attrs.headers + }, callbackFn); } } @@ -92,10 +98,10 @@ function startServer() { parseHttpRequest(c.toString()) .then((req) => { req.logSomething(); - return req; - }) - .then((req) => { - + req.forwardRequest((res) => { + console.log("Received response"); + console.log(res); + }); }) }); }) diff --git a/package-lock.json b/package-lock.json index f6c086f..289b5ac 100644 --- a/package-lock.json +++ b/package-lock.json @@ -831,6 +831,11 @@ "tweetnacl": "^0.14.3" } }, + "bluebird": { + "version": "3.5.3", + "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.5.3.tgz", + "integrity": "sha512-/qKPUQlaW1OyR51WeCPBvRnAlnZFUJkCSG5HzGnuIqhgyJtF+T94lFnn33eiazjRm2LAHVy2guNnaq48X9SJuw==" + }, "body-parser": { "version": "1.18.3", "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.18.3.tgz", @@ -4300,14 +4305,12 @@ "psl": { "version": "1.1.31", "resolved": "https://registry.npmjs.org/psl/-/psl-1.1.31.tgz", - "integrity": "sha1-6aqG0BAbWxBcvpOsa3hM1UcnYYQ=", - "dev": true + "integrity": "sha1-6aqG0BAbWxBcvpOsa3hM1UcnYYQ=" }, "punycode": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz", - "integrity": "sha1-tYsBCsQMIsVldhbI0sLALHv0eew=", - "dev": true + "integrity": "sha1-tYsBCsQMIsVldhbI0sLALHv0eew=" }, "qs": { "version": "6.5.2", @@ -4518,11 +4521,21 @@ } } }, + "request-promise": { + "version": "4.2.2", + "resolved": "https://registry.npmjs.org/request-promise/-/request-promise-4.2.2.tgz", + "integrity": "sha1-0epG1lSm7k+O5qT+oQGMIpEZBLQ=", + "requires": { + "bluebird": "^3.5.0", + "request-promise-core": "1.1.1", + "stealthy-require": "^1.1.0", + "tough-cookie": ">=2.3.3" + } + }, "request-promise-core": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/request-promise-core/-/request-promise-core-1.1.1.tgz", "integrity": "sha1-Pu4AssWqgyOc+wTFcA2jb4HNCLY=", - "dev": true, "requires": { "lodash": "^4.13.1" } @@ -5293,8 +5306,7 @@ "stealthy-require": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/stealthy-require/-/stealthy-require-1.1.1.tgz", - "integrity": "sha1-NbCYdbT/SfJqd35QmzCQoyJr8ks=", - "dev": true + "integrity": "sha1-NbCYdbT/SfJqd35QmzCQoyJr8ks=" }, "string-length": { "version": "2.0.0", @@ -5453,7 +5465,6 @@ "version": "2.5.0", "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-2.5.0.tgz", "integrity": "sha1-zZ+yoKodWhK0c72fuW+j3P9lreI=", - "dev": true, "requires": { "psl": "^1.1.28", "punycode": "^2.1.1" diff --git a/package.json b/package.json index cc5999d..05cc650 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "license": "MIT", "dependencies": { "express": "^4.16.4", + "request-promise": "^4.2.2", "winston": "^3.1.0" }, "devDependencies": {