Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Andreas Schleifer committed Jul 4, 2014
0 parents commit 828f05c
Show file tree
Hide file tree
Showing 7 changed files with 490 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/.idea
/data
/logs
/tmp

config.js

*.log
101 changes: 101 additions & 0 deletions Logger.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
var fs = require('fs');

function Logger(config) {
"use strict";

this._level_error = 0;
this._level_warning = 1;
this._level_notice = 2;
this._level_debug = 3;

this._file = null;

this._level = config.level;
this._debugKeys = config.debugKeys;
this._console = config.console;

if (null !== config.file) {
this._file = fs.createWriteStream(config.file, {
flags: 'a+'
});
this._file.on('error', function (err) {
console.log('Error on open log file: ', err.message);
});
}
}

Logger.prototype.destroy = function () {
"use strict";

if (null !== this._file) {
this._file.end();
}
};

Logger.prototype.error = function (msg) {
"use strict";

if (this._level < this._level_error) {
return;
}

this._logConsole('ERROR: ' + msg);
this._logFile('ERROR: ' + msg);
};

Logger.prototype.warning = function (msg) {
"use strict";

if (this._level < this._level_warning) {
return;
}

this._logConsole('WARNING: ' + msg);
this._logFile('WARNING: ' + msg);
};

Logger.prototype.notice = function (msg) {
"use strict";

if (this._level < this._level_notice) {
return;
}

this._logConsole('NOTICE: ' + msg);
this._logFile('NOTICE: ' + msg);
};

Logger.prototype.debug = function (key, msg) {
"use strict";

if (this._level < this._level_debug) {
return;
}

if (0 !== this._debugKeys.length
&& -1 === this._debugKeys.indexOf(key)
) {
return;
}

this._logConsole('DEBUG (' + key + '): ' + msg);
this._logFile('DEBUG (' + key + '): ' + msg);
};

Logger.prototype._logConsole = function (msg) {
"use strict";

if (true === this._console) {
console.log(msg);
}
};

Logger.prototype._logFile = function (msg) {
"use strict";

if (null !== this._file) {
this._file.write(msg + "\n", 'utf-8');
}
};

module.exports = Logger;
50 changes: 50 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# HTTP Proxy

## Setup

`npm install`

Copy `config.js.default` to `config.js` and modify to the desired values

## Run

`node http-proxy.js`

## Configure

module.exports = {
ip: 'proxy.example.com', // this is what the
port: 80, // proxy will listen to

sourceServer: 'somehost.com', // this is what the proxy
sourcePort: 80, // will read from

sourceTimeout: 2000, // timeout for requests
// to source (ms)

log: { // logging:

file: './http-proxy.log', // set to null to not use
// file logging

console: true, // set to false to not
// log to stdout

level: 0, // 0: error, 1: warnings
// 2: notices, 3: debug

debugKeys: [ // Empty Array: log all debug

'Request', // Special keys to be debugged
'CacheSize', // ^^
'GarbageCollection' // ^^
]
},
cacheSize: 100, // Number of resources
// to be cached before
// evictions will occure

garbageCollectionInterval: 1000 // intervall with that the
// garbage collection will evict
// entries
};
Loading

0 comments on commit 828f05c

Please sign in to comment.