Update client clientController to better handle no ID

This commit is contained in:
Logan Cusano
2023-06-18 16:26:55 -04:00
parent c5a7131063
commit dd5b442377

View File

@@ -67,6 +67,11 @@ async function checkLocalIP() {
* Checks the config file for all required fields or gets and updates the required fields
*/
exports.checkConfig = async function checkConfig() {
if (!runningClientConfig.id || runningClientConfig.id == 0 || runningClientConfig.id == '0') {
updateConfig('id', "");
runningClientConfig.id = null;
}
if (!runningClientConfig.ip) {
const ipAddr = await checkLocalIP();
updateConfig('ip', ipAddr);
@@ -97,7 +102,7 @@ exports.checkIn = async () => {
await this.checkConfig();
// Check if there is an ID found, if not add the node to the server. If there was an ID, check in with the server to make sure it has the correct information
try {
if (runningClientConfig.id === 0) {
if (!runningClientConfig?.id || runningClientConfig.id == null) {
// ID was not found in the config, creating a new node
reqOptions = new requestOptions("/nodes/newNode", "POST");
sendHttpRequest(reqOptions, JSON.stringify(), (responseObject) => {
@@ -118,6 +123,7 @@ exports.checkIn = async () => {
// ID is in the config, checking in with the server
reqOptions = new requestOptions("/nodes/nodeCheckIn", "POST");
sendHttpRequest(reqOptions, JSON.stringify(runningClientConfig), (responseObject) => {
log.DEBUG("Check In Respose: ", responseObject);
if (responseObject.statusCode === 202) {
// Server accepted an update
}