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QAAQ,EAAK,EAAU,GAEpD,CACA,OAAO,CACT,CAmDkB,CAAc,EAAe,GACrC,EAAI,MAAM,EAAO,SACnB,IACA,EAAc,GAAG,OAAO,WACtB,EAAI,KACN,GACH,IACD,EAAI,KAAK,EAEb,GAGF","file":"/npm/jelly-proxy@0.3.0/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.37.0.\n * Original file: /npm/jelly-proxy@0.3.0/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","var http = require('http')\n  , url = require('url')\n\nvar DEFAULTS = {\n  tag : \"</body>\"\n, payload : \"\"\n}\n\nmodule.exports = function createServer(opts, cb, port){\n\n  var deployPayload = function(resp, chunk){\n    // modify the html content\n    if (resp.headers['content-type'] && resp.headers['content-type'].indexOf(\"text/html\") != -1) {\n      var tag = opts.tag || DEFAULTS.tag\n        , payload = opts.payload || DEFAULTS.payload\n  \n      if (typeof(payload) == 'function'){\n        payload = payload();\n      }\n        \n      if (chunk.toString().indexOf(tag)){\n        chunk = chunk.toString().replace(tag, payload + tag);\n      }\n    }\n    return chunk\n  }\n\n  var server  = http.createServer(function (req, res) {\n    if (opts.logger){\n      opts.logger(req);\n    }\n\n    var ip = req.connection.remoteAddress;\n    var uri = url.parse(req.url, true);\n\n    var pathname = uri.search ? uri.pathname + uri.search : uri.pathname;\n    if (pathname.indexOf(\"_jelly\") == 0 || pathname.indexOf(\"/_jelly\") == 0){\n      // Special Case URL : Call the callback and let them deal with it...\n      return cb(req, res);\n\n    } else {\n      // Actual proxying happens here\n      req.headers['accept-encoding'] = \"text/html\";  // Stop from requesting gzip\n\n      // allow additional default headers\n      var headers={},h;\n\n      for(h in req.headers)\n        headers[h]=req.headers[h];\n\n      if(opts.defaultHeaders)\n        for(h in opts.defaultHeaders){\n          headers[h]=_this.default_headers[h];\n        }\n\n      var _port = uri.port\n       var proxyRequest = http.request({\n          port: port\n        , hostname: uri.hostname\n        , method: req.method\n        , path: pathname\n        , headers: headers\n        }\n        , function getProxyRequest(proxyResponse){\n\n          proxyRequest.on(\"error\", function (e) {\n            if (!res._header) {\n              res.writeHead(502, {})\n              res.end();\n            } else {\n              res.end();\n              console.error(\"[jelly-proxy] client error after writeHead was called. \", e.stack);\n            }\n          })\n\n          proxyResponse.addListener(\"data\", function (chunk) {\n            chunk = deployPayload(proxyResponse, chunk)\n            res.write(chunk, 'binary');\n          })\n          proxyResponse.on(\"end\", function(){\n            res.end()\n          })\n       })\n      req.pipe(proxyRequest);\n    } // End if _jelly\n  }) // End createServer\n\n  return server\n}\n"]}