Skip to content

Commit

Permalink
Merge pull request #2 from raghu12133/master
Browse files Browse the repository at this point in the history
Added ngrok support
  • Loading branch information
subwiz committed Dec 8, 2016
2 parents 3739c72 + 49938b2 commit 1e43032
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ When the above command is executed, any URL that is hit at http://localhost:3000
-C, --cors Add CORS headers to response. Optional Allow-Origin URL as param. Default is '*'.
-H, --header * Response header in the format 'header:value'.
-s, --status-code Response status code. Default is '200'.
-n, --ngrok Provides an ngrok tunnel url for the running server.
-v, --version Display anyurlhttpserver version.
-h, --help Output usage information.
Expand Down
21 changes: 20 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
'use strict';

var fs = require('fs');
var ngrokTunnel = require('ngrok');

// Constants:
const DEF_CONTENT = '{"hello": "world"}';
Expand Down Expand Up @@ -33,6 +34,8 @@ prg.addOpt('C', 'cors',
prg.addOpt('H', 'header',
`* Response header in the format 'header:value'.`,
{hasArg: true, multiArg: true});
prg.addOpt('n', 'ngrok',
`Provides an ngrok tunnel url for the running server.`);
prg.addOpt('s', 'status-code',
`Response status code. Default is '${DEF_STATUS}'.`,
{hasArg: true});
Expand Down Expand Up @@ -128,6 +131,15 @@ var corsUrl = (function() {
}
})();

var ngrok = (function() {
if(res.gopts.has('n')) {
return true;
}
else {
return false;
}
})();

// Web server start:
var express = require('express');
var app = express();
Expand All @@ -154,4 +166,11 @@ app.all('/*', function(req, res){
});

console.log(`Starting server in port ${port}.`);
app.listen(port);
app.listen(port, function(){
if (ngrok) {
ngrokTunnel.connect(port, function (err, url) {
console.log('\nngrok url:');
console.log(url);
});
}
});
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
},
"dependencies": {
"express": "^4.13.4",
"wiz-cliparse": "^0.5.4"
"wiz-cliparse": "^0.5.4",
"ngrok" : "2.2.4"
},
"devDependencies": {
"chai": "^3.5.0",
Expand Down

0 comments on commit 1e43032

Please sign in to comment.