Skip to content

Commit

Permalink
🐛 Add ability to specify port for Electron app #401
Browse files Browse the repository at this point in the history
  • Loading branch information
wwwredfish committed Apr 6, 2016
1 parent c8b6b17 commit 009d432
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
22 changes: 15 additions & 7 deletions electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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
);
Expand All @@ -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();
Expand Down
10 changes: 5 additions & 5 deletions server.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
'use strict';
const PORT = 9100;

var finalhandler = require('finalhandler'),
http = require('http'),
serveStatic = require('serve-static'),
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);
};

0 comments on commit 009d432

Please sign in to comment.