Skip to content

Commit

Permalink
Allow app host and base URL to be configured.
Browse files Browse the repository at this point in the history
  • Loading branch information
skewart committed Dec 21, 2015
1 parent 4722fb3 commit 4e75f58
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,15 @@ $ npm install
This service requires to be configured using environment variables:

```
# Set the port for the service
# Set the port for the service (default is 5000)
$ export PORT=6000
# Set the host for the service (default is 0.0.0.0)
$ export HOST=127.0.0.1
# Set a base URL for the service (default is '/')
$ export BASE_URL=/release
# Access token for the GitHub API (requires permissions to access the repository)
# If the repository is public you do not need to provide an access token
# you can also use GITHUB_USERNAME and GITHUB_PASSWORD
Expand Down
14 changes: 8 additions & 6 deletions bin/web.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ var basicAuth = require('basic-auth');
var Analytics = require('analytics-node');
var nuts = require('../');

const
BASE_URL = process.env.BASE_URL || '/',
PORT = process.env.PORT || 5000,
HOST = process.env.HOST || '0.0.0.0';

var app = express();

var apiAuth = {
Expand Down Expand Up @@ -70,7 +75,7 @@ var myNuts = nuts({
}
});

app.use(myNuts.router);
app.use(BASE_URL, myNuts.router);

// Error handling
app.use(function(req, res, next) {
Expand Down Expand Up @@ -99,9 +104,6 @@ app.use(function(err, req, res, next) {
});
});

var server = app.listen(process.env.PORT || 5000, function () {
var host = server.address().address;
var port = server.address().port;

console.log('Listening at http://%s:%s', host, port);
var server = app.listen(PORT, HOST, function () {
console.log('Listening at http://%s:%s%s', HOST, PORT, BASE_URL);
});

0 comments on commit 4e75f58

Please sign in to comment.