goldilocks.js/lib/modules/http.js

35 lines
1005 B
JavaScript
Raw Normal View History

2017-04-27 22:05:34 +00:00
'use strict';
module.exports.create = function (deps, conf) {
// This should be able to handle things like default web path (i.e. /srv/www/hostname),
// no-www redirect, and transpilation of static assets (i.e. cached versions of raw html)
// but right now it's a very dumb proxy
function createConnection(conn) {
var opts = conn.__opts;
var newConn = deps.net.createConnection({
port: conf.http.proxy.port
, host: '127.0.0.1'
, servername: opts.servername
, data: opts.data
, remoteFamily: opts.family || conn.remoteFamily
, remoteAddress: opts.address || conn.remoteAddress
, remotePort: opts.port || conn.remotePort
}, function () {
//console.log("[=>] first packet from tunneler to '" + cid + "' as '" + opts.service + "'", opts.data.byteLength);
// this will happen before 'data' is triggered
//newConn.write(opts.data);
});
newConn.pipe(conn);
conn.pipe(newConn);
}
return {
emit: function (type, conn) {
createConnection(conn);
}
};
};