-
-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Andreas Bräu <ab@andi95.de>
- Loading branch information
Showing
5 changed files
with
67 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,54 @@ | ||
var app = require('../app'); | ||
var system = require('../system'); | ||
|
||
var mongoose = require('mongoose'); | ||
|
||
const Errors = { | ||
DBERROR: 'DBERROR' | ||
} | ||
|
||
exports.gethealth = function(req, res) { | ||
const mongoose_state = mongoose.connection.readyState | ||
var errors = collectErrors(); | ||
if (errors.length == 0) { | ||
res.status(200).json({ | ||
status: "OK", | ||
mongoose: mongoose_state | ||
}); | ||
exports.gethealth = function (req, res) { | ||
const isHealthEndpointEnabled = system.isHealthEndpointEnabled(); | ||
if (!isHealthEndpointEnabled) { | ||
return res.status(404).send("not found"); | ||
} else { | ||
return res.status(500).json({ | ||
status: "Not OK", | ||
mongoose: mongoose_state, | ||
errors: errors | ||
}); | ||
} | ||
const mongoose_state = mongoose.connection.readyState | ||
var errors = collectErrors(); | ||
if (errors.length == 0) { | ||
return res.status(200).json({ | ||
status: "OK", | ||
mongoose: mongoose_state | ||
}); | ||
} else { | ||
return res.status(500).json({ | ||
status: "Not OK", | ||
mongoose: mongoose_state, | ||
errors: errors | ||
}); | ||
} | ||
|
||
function collectErrors() { | ||
var errors = []; | ||
switch (mongoose_state) { | ||
case 0: | ||
errors.push({ | ||
error: Errors.DBERROR, | ||
message: "mongodb disconnected" | ||
}); | ||
break; | ||
case 2: | ||
errors.push({ | ||
error: Errors.DBERROR, | ||
message: "mongodb connecting" | ||
}); | ||
break; | ||
case 3: | ||
errors.push({ | ||
error: Errors.DBERROR, | ||
message: "mongodb disconnecting" | ||
}); | ||
break; | ||
}; | ||
return errors; | ||
function collectErrors() { | ||
var errors = []; | ||
switch (mongoose_state) { | ||
case 0: | ||
errors.push({ | ||
error: Errors.DBERROR, | ||
message: "mongodb disconnected" | ||
}); | ||
break; | ||
case 2: | ||
errors.push({ | ||
error: Errors.DBERROR, | ||
message: "mongodb connecting" | ||
}); | ||
break; | ||
case 3: | ||
errors.push({ | ||
error: Errors.DBERROR, | ||
message: "mongodb disconnecting" | ||
}); | ||
break; | ||
}; | ||
return errors; | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters