Skip to content

Commit 3277ad7

Browse files
Angelo ManganielloAngelo Manganiello
authored andcommitted
fix management on port and variables for electron-app
1 parent e82be59 commit 3277ad7

File tree

4 files changed

+21
-11
lines changed

4 files changed

+21
-11
lines changed

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ Moreover, to use the automatic Travis deploy integration, you have only to repla
2222

2323
## NEWS
2424

25+
* 05/08/2018 Improve electron-app with priority on .env else on electron.app.config.json file
26+
2527
* 02/08/2018 Fix bug on reload of electron-client project with [Issue 9](https://github.com/amanganiello90/java-angular-web-app/issues/9).
2628

2729
* 04/07/2018 Added spring boot **swagger-ui** enabled on _/swagger-ui.html_ endpoint
@@ -42,7 +44,6 @@ May 30,2018 | **Release 1.0** | available from [GitHub](https://github.com/aman
4244

4345
## NEXT DEVELOPMENTS (checked in progress)
4446

45-
- [ ] Need to manage better electron.app.config.json and .env variables for electron-app
4647
- [ ] Create api server in cordova with [cordova plugin webserver](https://github.com/bykof/cordova-plugin-webserver) and [lockijs db](https://github.com/techfort/LokiJS)
4748
- [ ] Create ui tests with [java cucumber](https://examples.javacodegeeks.com/core-java/junit/junit-cucumber-example/)
4849
- [ ] Create api and ui tests in node app with a e2e framework
@@ -355,7 +356,7 @@ After built your front-end app with the **-Pbuild-ui** profile (or with *npm run
355356

356357
In this way **your frontend app with the express server side**, is running in the electron container. You can read log in its window with **F1 keyword**.
357358

358-
> The express server is a child spawn localhost process that is in listening in the port declared in the _process.env.PORT_ variable, else it uses the port declared in the **electron-app/electron.app.config.json** file.
359+
> The express server is a child spawn localhost process that is in listening in the port declared in the _process.env.PORT_ variable, else it uses the port declared in the **electron-app/electron.app.config.json** file. Every variable of .env file overwrites the electron.app.config.json definitions.
359360
So you can also open the browser on _localhost:8081_ (default port) to inspect page.
360361

361362

@@ -377,8 +378,8 @@ After this, you will have a single **electron-app 1.0.0** (for windows will be a
377378
**The file created is a standalone distributable desktop app that not require Node or JRE on your machine to be executed.**
378379
In this way **your frontend app with the express server side**, is running in the electron container. You can read log in its window with **F1 keyword**.
379380

380-
> The express server is a child spawn localhost process that is in listening in the port declared in the _process.env.PORT_ variable, else it uses the port declared in the **electron-app/electron.app.config.json** file.
381-
So you can also open the browser on _localhost:8081_ (default port) to inspect page.
381+
> The express server is a child spawn localhost process that is in listening in the port declared in the _process.env.PORT_ variable, else it uses the port declared in the **electron-app/electron.app.config.json** file. Every variable of .env file overwrites the electron.app.config.json definitions.
382+
So you can also open the browser on _localhost:8081_ (default port) to inspect page.
382383

383384

384385
#### Spring boot jar electron live mode

electron-app/api/config/database.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@ const database = {
55
};
66

77
function getDbUrl() {
8-
9-
if (process.env.MONGO_EMBEDDED === 'true')
8+
let appConfig= require(__dirname+'/../../electron.app.config.json');
9+
if (appConfig.MONGO_EMBEDDED === 'true' && process.env.MONGO_EMBEDDED !== 'false')
1010
return 'mongodb://' + __dirname;
11+
12+
if(process.env.MONGO_DB_URI!==undefined)
13+
return process.env.MONGO_DB_URI
1114

12-
return process.env.MONGO_DB_URI;
15+
return appConfig.MONGO_DB_URI;
1316
}
1417

1518
module.exports = database;

electron-app/api/index.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@ const express = require('express');
22
const app = express();
33
require('dotenv').config();
44
let appConfig= require(__dirname+'/../electron.app.config.json');
5-
const port = appConfig.PORT || 8000;
5+
let port = appConfig.PORT || 8000;
6+
if(process.env.PORT!==undefined){
7+
port=process.env.PORT;
8+
}
69
const environment = process.env.NODE_ENV || 'dev';
7-
const configDB = require(__dirname+'/config/database');
8-
if (appConfig.MONGO_EMBEDDED === 'true'){
10+
let configDB = require(__dirname+'/config/database');
11+
if (appConfig.MONGO_EMBEDDED === 'true' && process.env.MONGO_EMBEDDED !== 'false'){
912
require('tungus');
1013
}
1114
const morgan = require('morgan');

electron-app/index.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,10 @@
6262

6363
require('dotenv').config();
6464
var appConfig= require(__dirname+'/electron.app.config.json');
65-
const port = appConfig.PORT || 8000;
65+
let port = appConfig.PORT || 8000;
66+
if(process.env.PORT!==undefined){
67+
port=process.env.PORT;
68+
}
6669

6770
const expressAppUrl = "http://localhost:"+port,
6871

0 commit comments

Comments
 (0)