Skip to content

Commit

Permalink
Enable running multiple node-red instances on the same host.
Browse files Browse the repository at this point in the history
  • Loading branch information
helander committed Feb 7, 2024
1 parent 7dcb498 commit 46c3a8d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion config.schema.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"pluginAlias": "NodeRedHomebridgePlugin",
"pluginType": "platform",
"singular": true,
"singular": false,
"schema": {
"type": "object",
"properties": {
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"private": false,
"displayName": "Node Red plugin for Homebridge",
"name": "@helander/homebridge-node-red",
"version": "2.0.1",
"version": "2.1.0",
"description": "Run Node Red inside Homebridge.",
"license": "Apache-2.0",
"repository": {
Expand Down
15 changes: 12 additions & 3 deletions src/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,23 @@ export class NodeRedHomebridgePlatform implements DynamicPlatformPlugin {
flowFile: 'flows.json',
httpAdminRoot:'/red',
httpNodeRoot: '/api',
userDir:`${this.storagePath}/nodered`,
userDir:`${this.storagePath}/nodered-${this.port}`,
functionGlobalContext: { }, // enables global context
};

// On first startup, create a hb-conf node representing the local homebridge.
// setup userDir and manage migration from old userDir naming
const oldUserDir = `${this.storagePath}/nodered`;
if (!fs.existsSync(settings.userDir)) {
fs.mkdirSync(settings.userDir);
if (!fs.existsSync(oldUserDir)) {
fs.mkdirSync(settings.userDir);
this.log.info(`User directory created at ${settings.userDir}`);
} else {
fs.renameSync(oldUserDir, settings.userDir);
this.log.info(`User directory moved from ${oldUserDir} to ${settings.userDir}`);
}
}

// On first startup, create a hb-conf node representing the local homebridge.
const flowFilePath = `${settings.userDir}/${settings.flowFile}`;
if (!fs.existsSync(flowFilePath)) {
this.log.info('Flows file did not exist => create one with a hb-config included');
Expand Down

0 comments on commit 46c3a8d

Please sign in to comment.