diff --git a/.http-console b/.http-console new file mode 100644 index 0000000..a2b2591 --- /dev/null +++ b/.http-console @@ -0,0 +1,2 @@ +Host: localhost:3000 +Content-Type: application/json diff --git a/lib/http-console.js b/lib/http-console.js index 73cfb78..e75462b 100644 --- a/lib/http-console.js +++ b/lib/http-console.js @@ -55,10 +55,51 @@ this.Console.prototype = new(function () { process.exit(0); }); + this.loadConfig(); + this.prompt(); return this; }; + + /** + * Finds and runs http-console commands on start up + * + * The three locations checked are, in order: + * + * 1. /etc/.http-console + * 2. $HOME/.http-console + * 3. $PWD/.http-console + * + * Commands found in later files overwrite previous ones. Examples of + * commands run: + * + * Content-Type: application/json + * Authorization: AWS AKIAIOSFODNN7EXAMPLE:frJIUN8DYpKDtOLCwo//yllqDzg= + * + */ + this.loadConfig = function() { + var that = this; + var file = '/.http-console'; + var paths = [ + '/etc' + file, + process.env['HOME'] + file, + process.cwd() + file + ]; + + paths.forEach(function(path) { + if (fs.existsSync(path)) { + var data = fs.readFileSync(path, 'utf-8'); + var lines = data.split("\n"); + lines.forEach(function(line) { + if (line.trim() != '') { + that.exec(line); + } + }) + } + }); + }; + this.welcome = function () { sys.puts("> " + ("http-console " + exports.version).bold, "> Welcome, enter .help if you're lost.",