Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var http = require("http");
- var net = require("net");
- var httpAddress = "0.0.0.0";
- var httpPort = "8001";
- var getAgent = function() {
- return undefined;
- var agent;
- return function() {
- if (!agent) {
- agent = new http.Agent();
- agent.createConnection = function(options) {
- var socket = net.createConnection(options);
- socket.on("error", function(err) {
- console.log("AHA", err);
- });
- return socket;
- }
- }
- return agent;
- }();
- }
- server = http.createServer(function (req, res) {
- console.log("GOT REQUEST");
- var agent = getAgent();
- var postBody = JSON.stringify({});
- var options = {
- hostname: '192.168.1.11',
- port: 80,
- path: '/upload',
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- 'Content-Length': postBody.length
- },
- agent: agent,
- };
- var backendRequest = http.request(options, function(res) {
- console.log("GOT RESPONSE");
- });
- backendRequest.on("socket", function(socket) {
- console.log("GOT SOCKET");
- socket.on("error", function(err) {
- console.log("SOCKET ERROR", err);
- });
- });
- backendRequest.on("connect", function() {
- console.log("CONNECT");
- });
- backendRequest.on("error", function(e) {
- console.log("ERR", e);
- res.end("watt");
- });
- backendRequest.write(postBody);
- });
- server.listen(httpPort, httpAddress);
- console.log("Server running at http://<ip-address>:" + httpPort + "/");
- // execute "curl --max-time 5 http://localhost:8001; curl --max-time 5 http://localhost:8001" on console to trigger error
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement