Skip to content

Commit 4416a8e

Browse files
committed
Allow dynamic domain for openflow-nodered
1 parent a4f656b commit 4416a8e

8 files changed

Lines changed: 40 additions & 4 deletions

File tree

OpenFlowNodeRED/noderedlocal.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ saml_issuer=uri:localhost.openrpa.dk
1010
websocket_max_package_count=1048576
1111
api_ws_url=ws://localhost.openrpa.dk
1212
domain=localhost.openrpa.dk
13+
domain_use_ip_from_network=
1314
protocol=http
1415
jwt=
1516
# if you have a certificate then add the info below, update domain and set protocol=https

OpenFlowNodeRED/noderedremote.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ saml_issuer=uri:app.openiap.io
1010
websocket_max_package_count=1048576
1111
api_ws_url=wss://app.openiap.io
1212
domain=localhost.openrpa.dk
13+
domain_use_ip_from_network=
1314
protocol=http
1415
jwt=
1516
# if you have a certificate then add the info below, update domain and set protocol=https

OpenFlowNodeRED/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "openflow-nodered",
3-
"version": "1.1.03",
3+
"version": "1.1.04",
44
"description": "Simple wrapper around NodeRed, RabbitMQ and MongoDB to support a more scaleable NodeRed implementation.\r Also the \"backend\" for [OpenRPA](https://github.com/skadefro/OpenRPA)",
55
"main": "index.js",
66
"scripts": {

OpenFlowNodeRED/src/Config.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as fs from "fs";
44
import * as path from "path";
55
import { fetch, toPassportConfig } from "passport-saml-metadata";
66
import { NoderedUtil } from "openflow-api";
7+
const { networkInterfaces } = require('os');
78
export class Config {
89
public static getversion(): string {
910
var versionfile: string = path.join(__dirname, "VERSION");
@@ -76,6 +77,7 @@ export class Config {
7677
public static port: number = parseInt(Config.getEnv("port", "1880"));
7778
public static nodered_port: number = parseInt(Config.getEnv("nodered_port", "0"));
7879
public static domain: string = Config.getEnv("domain", "localhost");
80+
public static domain_use_ip_from_network: string = Config.getEnv("domain_use_ip_from_network", ""); // grab ip address from this adaptor and use for domain
7981
public static protocol: string = Config.getEnv("protocol", "http");
8082
public static nodered_domain_schema: string = Config.getEnv("nodered_domain_schema", "");
8183
public static noderedusers: string = Config.getEnv("noderedusers", "");
@@ -113,6 +115,20 @@ export class Config {
113115

114116

115117
public static baseurl(): string {
118+
if (!NoderedUtil.IsNullEmpty(Config.domain_use_ip_from_network)) {
119+
Config.domain_use_ip_from_network = Config.domain_use_ip_from_network.toLowerCase();
120+
const nets = networkInterfaces();
121+
for (const name of Object.keys(nets)) {
122+
for (const net of nets[name]) {
123+
// skip over non-ipv4 and internal (i.e. 127.0.0.1) addresses
124+
if (net.family === 'IPv4' && !net.internal) {
125+
if (name.toLowerCase() == Config.domain_use_ip_from_network) {
126+
Config.domain = net.address;
127+
}
128+
}
129+
}
130+
}
131+
}
116132
if (NoderedUtil.IsNullEmpty(Config.domain)) {
117133
if (Config.nodered_sa === null || Config.nodered_sa === undefined || Config.nodered_sa === "") {
118134
var matches = Config.nodered_id.match(/\d+/);

OpenFlowNodeRED/src/cli.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,35 @@ const optionDefinitions = [
1717
{ name: 'run', type: Boolean },
1818
{ name: 'name', type: String, defaultOption: true },
1919
{ name: 'config', type: String },
20-
{ name: 'inspect', type: String }
20+
{ name: 'inspect', type: String },
21+
{ name: 'networks', type: Boolean }
2122
]
2223
const commandLineArgs = require('command-line-args');
2324

2425
const path = require('path');
2526
const readlineSync = require('readline-sync');
2627
const envfile = require('envfile')
28+
const { networkInterfaces } = require('os');
2729

2830

2931

3032
var options = null;
3133
try {
3234
options = commandLineArgs(optionDefinitions);
3335
if (!options.init) {
36+
if (options.networks) {
37+
const nets = networkInterfaces();
38+
for (const name of Object.keys(nets)) {
39+
for (const net of nets[name]) {
40+
// skip over non-ipv4 and internal (i.e. 127.0.0.1) addresses
41+
if (net.family === 'IPv4' && !net.internal) {
42+
//console.log(name, net);
43+
console.log(name, net.address);
44+
}
45+
}
46+
}
47+
process.exit();
48+
}
3449
if (options.name == null || options.name == "") throw new Error("Name is mandatory");
3550
if (options.name.endsWith(".env")) options.name = options.name.substring(0, options.name.length - 4);
3651
(servicename as any) = options.name;

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.1.03
1+
1.1.04

gulpfile.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ gulp.task("browserify", function () {
4545
});
4646

4747
gulp.task("compose", shell.task([
48+
'echo "delete npmrc and cache"',
49+
"del OpenFlowNodeRED\\dist\\nodered\\.npmrc",
50+
'rmdir OpenFlowNodeRED\\dist\\.cache /s /q ',
4851
'gulp browserify',
4952
'gulp copyfiles1',
5053
'echo "compile OpenFlowNodeRED"',

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "openiap",
3-
"version": "1.1.03",
3+
"version": "1.1.04",
44
"description": "Simple wrapper around NodeRed, RabbitMQ and MongoDB to support a more scaleable NodeRed implementation.\r Also the \"backend\" for [OpenRPA](https://github.com/skadefro/OpenRPA)",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)