Permalink
Browse files

working simple example thing

  • Loading branch information...
1 parent 60118b3 commit caf37e6937cab283916b728ceeb0effdba5f3a70 @substack committed Nov 15, 2011
Showing with 74 additions and 2 deletions.
  1. +25 −0 example/simple.js
  2. +10 −2 index.js
  3. +13 −0 keys/certificate.pem
  4. +11 −0 keys/certrequest.csr
  5. +15 −0 keys/privatekey.pem
View
@@ -0,0 +1,25 @@
+var detector = require('../');
+var http = require('http');
+var https = require('https');
+
+var fs = require('fs');
+var opts = {
+ key : fs.readFileSync(__dirname + '/../keys/privatekey.pem'),
+ cert : fs.readFileSync(__dirname + '/../keys/certificate.pem'),
+};
+
+var servers = {
+ http : http.createServer(function (req, res) {
+ res.setHeader('content-type', 'text/plain');
+ res.end('I am an http server!');
+ }),
+ https : https.createServer(opts, function (req, res) {
+ res.setHeader('content-type', 'text/plain');
+ res.write('I AM TOTALLY SECURE AND STUFF YOU GUYS.');
+ res.end(' SELF SIGNED IS TOTALLY SECURE, WHATEVER.');
+ }),
+};
+
+servers.http.listen(4051);
+servers.https.listen(4052);
+detector({ http : 4051, https : 4052 }).listen(4050);
View
@@ -2,14 +2,22 @@ var net = require('net');
var EventEmitter = require('events').EventEmitter;
var exports = module.exports = function (opts) {
- var server = net.createServer(detect, function (proto, stream, buf) {
+ var server = net.createServer(function (stream) {
+ detect(stream, handler);
+ });
+
+ function handler (proto, stream, buf) {
var target = opts[proto];
if (typeof target === 'object' && target.write) {
target.write(buf);
stream.pipe(target);
target.pipe(stream);
}
else {
+ if (!Array.isArray(target)) {
+ target = [ target ];
+ }
+
stream.pause();
var c = net.createConnection.apply(null, target);
c.on('connect', function () {
@@ -19,7 +27,7 @@ var exports = module.exports = function (opts) {
stream.resume();
});
}
- });
+ }
return server;
};
View
@@ -0,0 +1,13 @@
+-----BEGIN CERTIFICATE-----
+MIICATCCAWoCCQD5tp1iWzpetzANBgkqhkiG9w0BAQUFADBFMQswCQYDVQQGEwJB
+VTETMBEGA1UECBMKU29tZS1TdGF0ZTEhMB8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f37e6

Please sign in to comment.