Skip to content

Commit

Permalink
Add ability to define host in a single config setting
Browse files Browse the repository at this point in the history
  • Loading branch information
fzaninotto committed May 22, 2014
1 parent ae3876c commit f2c171d
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 15 deletions.
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ Configuring
Uptime uses [node-config](https://github.com/lorenwest/node-config) to allow YAML configuration and environment support. Here is the default configuration, taken from `config/default.yaml`:

```yaml
url: 'http://localhost:8082'

mongodb:
server: localhost
database: uptime
Expand All @@ -92,9 +94,6 @@ analyzer:

autoStartMonitor: true

server:
port: 8082

plugins:
- ./plugins/console
- ./plugins/patternMatcher
Expand All @@ -105,8 +104,7 @@ plugins:
To modify this configuration, create a `development.yaml` or a `production.yaml` file in the same directory, and override just the settings you need. For instance, to run Uptime on port 80 in production, create a `production.yaml` file as follows:

```yaml
server:
port: 80
url: 'http://myDomain.com'
```
Node that Uptime works great behind a proxy - it uses the `http_proxy` environment variable transparently.
Expand Down
28 changes: 25 additions & 3 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/

var http = require('http');
var url = require('url');
var express = require('express');
var config = require('config');
var socketIo = require('socket.io');
Expand Down Expand Up @@ -136,14 +137,35 @@ fs.exists('./plugins/index.js', function(exists) {
});

module.exports = app;

var monitorInstance;

if (!module.parent) {
var port = process.env.PORT || config.server.port;
var serverUrl = url.parse(config.url);
var port;
if (config.server && config.server.port) {
console.error('Warning: The server port setting is deprecated, please use the url setting instead');
port = config.server.port;
} else {
port = serverUrl.port;
if (port === null) {
port = 80;
}
}
var port = process.env.PORT || port;
var host = process.env.HOST || serverUrl.hostname;
server.listen(port, function(){
console.log("Express server listening on port %d in %s mode", port, app.settings.env);
console.log("Express server listening on host %s, port %d in %s mode", host, port, app.settings.env);
});
server.on('error', function(e) {
if (monitorInstance) {
monitorInstance.stop();
process.exit(1);
}
});
}

// monitor
if (config.autoStartMonitor) {
require('./monitor');
monitorInstance = require('./monitor');
}
9 changes: 4 additions & 5 deletions config/default.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
url: 'http://localhost:8082'

mongodb:
server: localhost
database: uptime
Expand All @@ -19,9 +21,6 @@ analyzer:

autoStartMonitor: true

server:
port: 8082

plugins:
- ./plugins/console
- ./plugins/patternMatcher
Expand All @@ -44,9 +43,9 @@ email:
message:
from: # The message sender, e.g. 'Fred Foo <foo@blurdybloop.com>'
to: # The message recipient, e.g. 'bar@blurdybloop.com, baz@blurdybloop.com'
dashboardUrl: 'http://localhost:8082'
# The email plugin also uses the main `url` param for hyperlinks in the sent emails

basicAuth:
username: admin
password: password
verbose: true # only used in dev
verbose: true # only used in dev
1 change: 1 addition & 0 deletions lib/monitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ Monitor.prototype.start = function() {
*/
Monitor.prototype.stop = function() {
clearInterval(this.intervalForPoll);
console.log('Monitor ' + this.config.name + ' stopped');
};

/**
Expand Down
4 changes: 2 additions & 2 deletions plugins/email/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
* message:
* from: 'Fred Foo <foo@blurdybloop.com>'
* to: 'bar@blurdybloop.com, baz@blurdybloop.com'
* dashboardUrl: 'http://localhost:8082'
* # The email plugin also uses the main `url` param for hyperlinks in the sent emails
*/
var fs = require('fs');
var nodemailer = require('nodemailer');
Expand All @@ -67,7 +67,7 @@ exports.initWebApp = function(options) {
var renderOptions = {
check: check,
checkEvent: checkEvent,
url: config.dashboardUrl,
url: options.config.url,
moment: moment,
filename: filename
};
Expand Down

0 comments on commit f2c171d

Please sign in to comment.