Skip to content

Commit 252ee01

Browse files
committed
prepare for more dynamic nodered launching
1 parent b545d42 commit 252ee01

3 files changed

Lines changed: 13 additions & 4 deletions

File tree

OpenFlowNodeRED/src/Config.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ export class Config {
3131

3232
public static baseurl(): string {
3333
var matches = Config.nodered_id.match(/\d+/);
34-
Config.nodered_id = matches[matches.length - 1]; // Just grab the last number
34+
if (matches.length > 0) {
35+
Config.nodered_id = matches[matches.length - 1]; // Just grab the last number
36+
}
3537
if (Config.nodered_domain_schema != "") {
3638
Config.domain = Config.nodered_domain_schema.replace("$nodered_id$", Config.nodered_id)
3739
}

OpenFlowNodeRED/src/index.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,21 @@ process.on('unhandledRejection', up => {
3232
console.error(up);
3333
throw up
3434
});
35-
35+
function isNumeric(n) {
36+
return !isNaN(parseFloat(n)) && isFinite(n);
37+
}
3638
(async function (): Promise<void> {
3739
try {
3840
var socket: WebSocketClient = new WebSocketClient(logger, Config.api_ws_url);
3941
socket.events.on("onopen", async () => {
4042

4143
var q: SigninMessage = new SigninMessage();
42-
var user = new TokenUser(); user.name = "nodered" + Config.nodered_id; user.username = user.name;
44+
var user = new TokenUser();
45+
user.name = "nodered" + Config.nodered_id;
46+
if (!isNumeric(Config.nodered_id)) {
47+
user.name = Config.nodered_id;
48+
}
49+
user.username = user.name;
4350
q.jwt = Crypt.createToken(user);
4451
var msg: Message = new Message(); msg.command = "signin"; msg.data = JSON.stringify(q);
4552
var result: SigninMessage = await socket.Send<SigninMessage>(msg);

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.0.170
1+
0.0.171

0 commit comments

Comments
 (0)