|
38 | 38 | this.name = n.name; |
39 | 39 | this.port = n.port; |
40 | 40 | this.endpoint = n.endpoint; |
41 | | - this.users = n.users; |
| 41 | + this.usersFile = n.usersFile; |
42 | 42 | this.nodesetDir = n.nodesetDir; |
43 | 43 | this.autoAcceptUnknownCertificate = n.autoAcceptUnknownCertificate; |
44 | 44 | this.allowAnonymous = n.allowAnonymous; |
|
98 | 98 | let users = [{ username: "", password: "", roles: "" }]; // Empty as default |
99 | 99 | let savedAddressSpace = ""; |
100 | 100 |
|
101 | | - if (node.users && node.users.length > 0) { |
102 | | - verbose_log(chalk.yellow("Trying to load default users from file: ") + chalk.cyan(node.users) + chalk.yellow(" folder: ") + chalk.cyan(__dirname)); |
103 | | - if (fs.existsSync(node.users)) { |
104 | | - users = JSON.parse(fs.readFileSync(node.users)); |
| 101 | + if (node.usersFile && node.usersFile.length > 0) { |
| 102 | + verbose_log(chalk.yellow("Trying to load default users from file: ") + chalk.cyan(node.usersFile) + chalk.yellow(" folder: ") + chalk.cyan(__dirname)); |
| 103 | + if (fs.existsSync(node.usersFile)) { |
| 104 | + users = JSON.parse(fs.readFileSync(node.usersFile, "utf8")); |
105 | 105 | verbose_log(chalk.green("Loaded users: ") + chalk.cyan(JSON.stringify(users))); |
106 | | - setUsers(users); |
| 106 | + setUsers(); |
107 | 107 | } |
108 | 108 | else { |
109 | 109 | // Current working directory |
110 | | - let fileName = path.join(process.cwd(), node.users); |
111 | | - verbose_log(chalk.yellow("Trying to load default users from file: ") + chalk.cyan(node.users) + chalk.yellow(" folder: ") + chalk.cyan(fileName)); |
| 110 | + let fileName = path.join(process.cwd(), node.usersFile); |
| 111 | + verbose_log(chalk.yellow("Trying to load default users from file: ") + chalk.cyan(node.usersFile) + chalk.yellow(" folder: ") + chalk.cyan(fileName)); |
112 | 112 | if (fs.existsSync(fileName)) { |
113 | | - users = JSON.parse(fs.readFileSync(fileName)); |
| 113 | + users = JSON.parse(fs.readFileSync(fileName, "utf8")); |
114 | 114 | verbose_log(chalk.green("Loaded users: ") + chalk.cyan(JSON.stringify(users))); |
115 | | - setUsers(users); |
| 115 | + setUsers(); |
116 | 116 | } |
117 | 117 | else { |
118 | | - let fileName = path.join(process.cwd(), ".node-red", node.users); |
119 | | - verbose_log(chalk.yellow("Trying to load default users from file: ") + chalk.cyan(node.users) + chalk.yellow(" folder: ") + chalk.cyan(fileName)); |
| 118 | + let fileName = path.join(process.cwd(), ".node-red", node.usersFile); |
| 119 | + verbose_log(chalk.yellow("Trying to load default users from file: ") + chalk.cyan(node.usersFile) + chalk.yellow(" folder: ") + chalk.cyan(fileName)); |
120 | 120 | if (fs.existsSync(fileName)) { |
121 | | - users = JSON.parse(fs.readFileSync(fileName)); |
| 121 | + users = JSON.parse(fs.readFileSync(fileName, "utf8")); |
122 | 122 | verbose_log(chalk.green("Loaded users: ") + chalk.cyan(JSON.stringify(users))); |
123 | | - setUsers(users); |
| 123 | + setUsers(); |
124 | 124 | } |
125 | 125 | else { |
126 | | - verbose_log(chalk.red("File: " + node.users + " not found! You can inject users to server or add file to folder: " + fileName)); |
127 | | - node.error("File: " + node.users + " not found! You can inject users to server or add file to folder: " + fileName); |
| 126 | + verbose_log(chalk.red("File: " + node.usersFile + " not found! You can inject users to server or add file to folder: " + fileName)); |
| 127 | + node.error("File: " + node.usersFile + " not found! You can inject users to server or add file to folder: " + fileName); |
128 | 128 | } |
129 | 129 | } |
130 | 130 | } |
|
0 commit comments