Skip to content
This repository has been archived by the owner on Sep 10, 2022. It is now read-only.

Commit

Permalink
First crack at fixing #64
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Gaunt committed Dec 18, 2015
1 parent 450fa3c commit f7409fb
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 13 deletions.
1 change: 1 addition & 0 deletions app.js
Expand Up @@ -22,3 +22,4 @@ serverController.addEndpoint('/api*', new APIController(
));
// The static page controller serves the basic form of the pages
serverController.addEndpoint('/*', new StaticPageController());
serverController.startServer(process.env.PORT);
11 changes: 11 additions & 0 deletions gulp-tasks/nodemon.js
@@ -1,7 +1,18 @@
var gulp = require('gulp');
var nodemon = require('gulp-nodemon');
var env = require('gulp-env');

gulp.task('nodemon', function() {
const PROD_PORT = 8080;
const DEV_PORT = 8081;
// This results in different ports for prod and dev
var port = (GLOBAL.config.env === 'prod') ? PROD_PORT : DEV_PORT;
env({
vars: {
PORT: port
}
});

return nodemon({
script: 'app.js'
});
Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -25,6 +25,7 @@
"gulp": "^3.9.0",
"gulp-autoprefixer": "^3.1.0",
"gulp-bump": "^1.0.0",
"gulp-env": "^0.2.0",
"gulp-eslint": "^1.0.0",
"gulp-if": "^2.0.0",
"gulp-imagemin": "^2.3.0",
Expand Down
34 changes: 21 additions & 13 deletions server/controllers/server-controller.js
Expand Up @@ -9,12 +9,26 @@ function ServerController() {
layoutsDir: path.join(__dirname, '/../views/layouts'),
partialsDir: path.join(__dirname, '/../views/partials')
});
var expressServer = this.setUpServer(expressApp, handleBarsInstance);

// Set up the use of handle bars and set the path for views and layouts
expressApp.set('views', path.join(__dirname, '/../views'));
expressApp.engine('handlebars', handleBarsInstance.engine);
expressApp.set('view engine', 'handlebars');

// Define static assets path - i.e. styles, scripts etc.
expressApp.use('/',
express.static(path.join(__dirname + '/../../dist/')));

var expressServer = null;

this.getExpressApp = function() {
return expressApp;
};

this.setExpressServer = function(server) {
expressServer = server;
};

this.getExpressServer = function() {
return expressServer;
};
Expand All @@ -24,18 +38,12 @@ function ServerController() {
};
}

ServerController.prototype.setUpServer = function(app, handleBarsInstance) {
// Set up the use of handle bars and set the path for views and layouts
app.set('views', path.join(__dirname, '/../views'));
app.engine('handlebars', handleBarsInstance.engine);
app.set('view engine', 'handlebars');

// Define static assets path - i.e. styles, scripts etc.
app.use('/',
express.static(path.join(__dirname + '/../../dist/')));

console.log('Starting server on 8080');
return app.listen('8080');
ServerController.prototype.startServer = function(port) {
var server = this.getExpressApp().listen(port, () => {
var serverPort = server.address().port;
console.log('Server running on port ' + serverPort);
});
this.setExpressServer(server);
};

ServerController.prototype.addEndpoint = function(endpoint, controller) {
Expand Down

0 comments on commit f7409fb

Please sign in to comment.