-
-
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.
* add a health endpoint Signed-off-by: Andreas Bräu <ab@andi95.de> * make health endpoint configurable Signed-off-by: Andreas Bräu <ab@andi95.de> --------- Signed-off-by: Andreas Bräu <ab@andi95.de>
- Loading branch information
Showing
6 changed files
with
82 additions
and
3 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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
var system = require('../system'); | ||
|
||
var mongoose = require('mongoose'); | ||
|
||
const Errors = { | ||
DBERROR: 'DBERROR' | ||
} | ||
|
||
exports.gethealth = function (req, res) { | ||
const isHealthEndpointEnabled = system.isHealthEndpointEnabled(); | ||
if (!isHealthEndpointEnabled) { | ||
return res.status(404).send("not found"); | ||
} else { | ||
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; | ||
} | ||
} | ||
}; |
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