adding option to disable the info api

This commit is contained in:
Christian Kellner
2020-07-20 16:21:11 +02:00
parent e9b1eeae48
commit f1a00cf3bd
3 changed files with 13 additions and 6 deletions

View File

@@ -154,7 +154,7 @@ This makes sense for provider that only offer limited filter functions like Kala
# API
While Fredy is running, you can make use of the rest api provided on port `9998` to get information about the current status of Fredy.
#### http://localhost:9998/
Gives you an overview of running search jobs, their included enabled provider, last execution and the number of listings, found by each provider.
Gives you an overview of running search jobs, their included enabled provider, last execution and the number of listings, found by each provider. You can disable the api by setting `infoApi: false` within the config.
#### http://localhost:9998/ping
Should you ever need some health checks, this returns pong ;)

View File

@@ -1,5 +1,6 @@
{
"interval": 1,
"infoApi": true,
"jobs": {
"yourSearchJob": {
"notification": {

View File

@@ -3,6 +3,8 @@ const config = require('../../conf/config');
const { getLastJobExecution, getLastProviderExecution, getTotalNumberOfListings } = require('../services/store');
const PORT = 9998;
const service = require('restana')();
const enabled = config.infoApi == null ? false : config.infoApi;
service.use(bodyParser.json());
service.get('/', async (req, res) => {
@@ -55,8 +57,12 @@ service.get('/ping', function (req, res) {
res.send();
});
service.start(PORT).then(() => {
/* eslint-disable no-console */
console.info(`Started API service on port ${PORT}`);
/* eslint-enable no-console */
});
/* eslint-disable no-console */
if (enabled) {
service.start(PORT).then(() => {
console.info(`Started API service on port ${PORT}`);
});
} else {
console.info('Info Api is disabled.');
}
/* eslint-enable no-console */