Skip to content

Load http-console commands on startup #41

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .http-console
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Host: localhost:3000
Content-Type: application/json
41 changes: 41 additions & 0 deletions lib/http-console.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down