Skip to content

Commit

Permalink
Merge pull request #193 from tsmorgan/browser-sync-2
Browse files Browse the repository at this point in the history
Adding browser-sync to the prototyping kit.
  • Loading branch information
joelanman committed May 27, 2016
2 parents 899e07d + a1e6b16 commit d00b3b2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
13 changes: 5 additions & 8 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ exports.basicAuth = function(username, password) {
};
};

exports.findAvailablePort = function(app){
exports.findAvailablePort = function(app, callback){

var port = null;

Expand All @@ -51,10 +51,7 @@ exports.findAvailablePort = function(app){
portScanner.findAPortNotInUse(port, port+50, '127.0.0.1', function(error, availablePort) {

if (port == availablePort){

app.listen(port);
console.log('Listening on port ' + port + ' url: http://localhost:' + port);

callback(port);
} else {

// Default port in use - offer to change to available port
Expand All @@ -79,9 +76,9 @@ exports.findAvailablePort = function(app){
// User answers yes
port = availablePort;
fs.writeFileSync(__dirname+'/../.port.tmp', port);
app.listen(port);
console.log('Changed to port ' + port + ' url: http://localhost:' + port);
console.log('Changed to port ' + port);

callback(port);
} else {

// User answers no - exit
Expand All @@ -103,4 +100,4 @@ exports.forceHttps = function(req, res, next) {
return res.redirect(302, 'https://' + req.get('Host') + req.url);
}
next();
};
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"basic-auth": "^1.0.3",
"basic-auth-connect": "^1.0.0",
"body-parser": "^1.14.1",
"browser-sync": "^2.11.1",
"consolidate": "0.x",
"express": "4.13.3",
"express-nunjucks": "^0.9.3",
Expand Down
22 changes: 21 additions & 1 deletion server.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var path = require('path'),
express = require('express'),
browserSync = require('browser-sync'),
nunjucks = require('express-nunjucks'),
routes = require(__dirname + '/app/routes.js'),
favicon = require('serve-favicon'),
Expand Down Expand Up @@ -141,4 +142,23 @@ console.log("\nGOV.UK Prototype kit v" + releaseVersion);
console.log("\nNOTICE: the kit is for building prototypes, do not use it for production services.");

// start the app
utils.findAvailablePort(app);
utils.findAvailablePort(app, function(port) {
console.log('Listening on port ' + port + ' url: http://localhost:' + port);
if (env === 'production') {
app.listen(port);
} else {
app.listen(port-50,function()
{
browserSync({
proxy:'localhost:'+(port-50),
port:port,
ui:false,
files:['public/**/*.*','app/views/**/*.*'],
ghostmode:false,
open:false,
notify:false,
logLevel: "error"
});
});
}
});

0 comments on commit d00b3b2

Please sign in to comment.