balderdashy/sails — pull request #445 by dasher (2013-06-08 16:40:51+00:00)
Title: Allows for dynamic ports and semver style services

This change allows for a dynamic (function driven) port rather than a static value in config and also brings in the app version from the package.json file of the app (sails.config.version).

An example of its usage is with the [seaport](github.com/substack/seaport) semver registry (although it'll also allow dynamic hosting providers who provide a randomish port and webhook style versioned things).

Take the following snippet from config/application.js
```javascript
// Uses _.once to ensure we always get the same port
dynaport: _.once(function() {
var seaport = require("seaport");
var ports = seaport.connect('localhost', 9090);
return ports.register('web@'+sails.config.version);
}),

port: function() {
return sails.config.dynaport();
}
```

Out of the box it'll work with ports that are static or functions - so nothing wonky will happen for traditional sails apps.