diff --git a/electron.js b/electron.js index 76657ca83..d25cf0378 100644 --- a/electron.js +++ b/electron.js @@ -5,17 +5,25 @@ var app = require('app'), BrowserWindow = require('browser-window'), path = require('path'), menu = require('menu'), - openUrl = require('open'); + openUrl = require('open'), + port = 9000; -// Uncomment to enable helpful F12 Chrome inspector debugging -if (process.env.NODE_ENV === 'dev') { +// Port was provided +if (process.argv.indexOf('--port') >= 0) { + port = process.argv[process.argv.indexOf('--port') + 1]; +} + +// Show development tools +if (process.env.NODE_ENV === 'dev' || process.argv.indexOf('--dev') >= 0) { require('electron-debug')({ showDevTools: true }); } -// Start server -require('./server'); +// Start the server +if (process.argv.indexOf('--no-server') === -1) { + require('./server')(port); +} var menuTemplate = [{ label: 'Application', @@ -91,7 +99,7 @@ app.on('ready', function() { function checkUrl(url) { return ( - url.indexOf('localhost:9100') === -1 && + url.indexOf('localhost:' + port) === -1 && url.indexOf('oauth') === -1 && url.indexOf('sign_in') === -1 ); @@ -117,7 +125,7 @@ app.on('ready', function() { } // and load the index.html of the app. - mainWindow.loadURL('http://localhost:9100/'); + mainWindow.loadURL('http://localhost:' + port + '/'); // Open the DevTools. // mainWindow.openDevTools(); diff --git a/server.js b/server.js index c51ed5632..220d07e2e 100644 --- a/server.js +++ b/server.js @@ -1,5 +1,4 @@ 'use strict'; -const PORT = 9100; var finalhandler = require('finalhandler'), http = require('http'), @@ -7,13 +6,14 @@ var finalhandler = require('finalhandler'), serve, server; -serve = serveStatic(__dirname + '/dist', {index: ['index.html']}); +serve = serveStatic(__dirname + '/app', {index: ['index.html']}); server = http.createServer(function(req, res) { var done = finalhandler(req, res); serve(req, res, done); }); -server.listen(PORT); - -console.log('Server is running on port: ' + PORT); +module.exports = function(port) { + console.log('Server is running on port: ' + port); + return server.listen(port); +};