Structured /health Response (#4305)
* modifies /health to return json instead of OK * version removed!
This commit is contained in:
committed by
Florent Vilmart
parent
46af1b6955
commit
c0a81a88b7
@@ -8,7 +8,9 @@ describe('Server Url Checks', () => {
|
|||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
app.get('/health', function(req, res){
|
app.get('/health', function(req, res){
|
||||||
res.send('OK');
|
res.json({
|
||||||
|
status: 'ok'
|
||||||
|
});
|
||||||
});
|
});
|
||||||
app.listen(13376);
|
app.listen(13376);
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ import { SchemasRouter } from './Routers/SchemasRouter';
|
|||||||
import { SessionsRouter } from './Routers/SessionsRouter';
|
import { SessionsRouter } from './Routers/SessionsRouter';
|
||||||
import { UsersRouter } from './Routers/UsersRouter';
|
import { UsersRouter } from './Routers/UsersRouter';
|
||||||
import { PurgeRouter } from './Routers/PurgeRouter';
|
import { PurgeRouter } from './Routers/PurgeRouter';
|
||||||
import { AudiencesRouter } from './Routers/AudiencesRouter';
|
import { AudiencesRouter } from './Routers/AudiencesRouter';
|
||||||
|
|
||||||
import { ParseServerRESTController } from './ParseServerRESTController';
|
import { ParseServerRESTController } from './ParseServerRESTController';
|
||||||
import * as controllers from './Controllers';
|
import * as controllers from './Controllers';
|
||||||
@@ -137,7 +137,11 @@ class ParseServer {
|
|||||||
maxUploadSize: maxUploadSize
|
maxUploadSize: maxUploadSize
|
||||||
}));
|
}));
|
||||||
|
|
||||||
api.use('/health', (req, res) => res.sendStatus(200));
|
api.use('/health', (function(req, res) {
|
||||||
|
res.json({
|
||||||
|
status: 'ok'
|
||||||
|
});
|
||||||
|
}));
|
||||||
|
|
||||||
api.use('/', bodyParser.urlencoded({extended: false}), new PublicAPIRouter().expressRouter());
|
api.use('/', bodyParser.urlencoded({extended: false}), new PublicAPIRouter().expressRouter());
|
||||||
|
|
||||||
@@ -252,7 +256,13 @@ class ParseServer {
|
|||||||
if(Parse.serverURL) {
|
if(Parse.serverURL) {
|
||||||
const request = require('request');
|
const request = require('request');
|
||||||
request(Parse.serverURL.replace(/\/$/, "") + "/health", function (error, response, body) {
|
request(Parse.serverURL.replace(/\/$/, "") + "/health", function (error, response, body) {
|
||||||
if (error || response.statusCode !== 200 || body !== "OK") {
|
let json;
|
||||||
|
try {
|
||||||
|
json = JSON.parse(body);
|
||||||
|
} catch(e) {
|
||||||
|
json = null;
|
||||||
|
}
|
||||||
|
if (error || response.statusCode !== 200 || !json || json && json.status !== 'ok') {
|
||||||
/* eslint-disable no-console */
|
/* eslint-disable no-console */
|
||||||
console.warn(`\nWARNING, Unable to connect to '${Parse.serverURL}'.` +
|
console.warn(`\nWARNING, Unable to connect to '${Parse.serverURL}'.` +
|
||||||
` Cloud code and push notifications may be unavailable!\n`);
|
` Cloud code and push notifications may be unavailable!\n`);
|
||||||
|
|||||||
Reference in New Issue
Block a user