Browse Source

healthcheck 200

loopout2
Evan Feenstra 5 years ago
parent
commit
beaf8526b6
  1. 6
      dist/src/controllers/confirmations.js
  2. 2
      dist/src/controllers/confirmations.js.map
  3. 9
      dist/src/utils/res.js
  4. 2
      dist/src/utils/res.js.map
  5. 8
      src/controllers/confirmations.ts
  6. 11
      src/utils/res.ts

6
dist/src/controllers/confirmations.js

@ -150,7 +150,7 @@ function healthcheck(req, res) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
const pubkey = req.query.pubkey; const pubkey = req.query.pubkey;
if (!(pubkey && pubkey.length === 66)) { if (!(pubkey && pubkey.length === 66)) {
return res_1.failure(res, 'missing pubkey'); return res_1.failure200(res, 'missing pubkey');
} }
const owner = yield models_1.models.Contact.findOne({ where: { isOwner: true } }); const owner = yield models_1.models.Contact.findOne({ where: { isOwner: true } });
const amt = 10; const amt = 10;
@ -169,7 +169,7 @@ function healthcheck(req, res) {
yield network.signAndSend(opts); yield network.signAndSend(opts);
} }
catch (e) { catch (e) {
res_1.failure(res, e); res_1.failure200(res, e);
return; return;
} }
let i = 0; let i = 0;
@ -177,7 +177,7 @@ function healthcheck(req, res) {
if (i >= 15) { if (i >= 15) {
clearInterval(interval); clearInterval(interval);
delete heartbeats[pubkey]; delete heartbeats[pubkey];
res_1.failure(res, 'no confimration received'); res_1.failure200(res, 'no confimration received');
return; return;
} }
if (heartbeats[pubkey]) { if (heartbeats[pubkey]) {

2
dist/src/controllers/confirmations.js.map

File diff suppressed because one or more lines are too long

9
dist/src/utils/res.js

@ -18,4 +18,13 @@ function failure(res, e) {
res.end(); res.end();
} }
exports.failure = failure; exports.failure = failure;
function failure200(res, e) {
res.status(200);
res.json({
success: false,
error: (e && e.message) || e,
});
res.end();
}
exports.failure200 = failure200;
//# sourceMappingURL=res.js.map //# sourceMappingURL=res.js.map

2
dist/src/utils/res.js.map

@ -1 +1 @@
{"version":3,"file":"res.js","sourceRoot":"","sources":["../../../src/utils/res.ts"],"names":[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CAAC,CAAC;IAChB,GAAG,CAAC,IAAI,CAAC;QACP,OAAO,EAAE,KAAK;QACd,KAAK,EAAE,CAAC,CAAC,IAAE,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC;KAC3B,CAAC,CAAC;IACH,GAAG,CAAC,GAAG,EAAE,CAAC;AACZ,CAAC;AAEyB,gCAAU"}

8
src/controllers/confirmations.ts

@ -4,7 +4,7 @@ import * as socket from '../utils/socket'
import * as jsonUtils from '../utils/json' import * as jsonUtils from '../utils/json'
import * as network from '../network' import * as network from '../network'
import constants from '../constants' import constants from '../constants'
import { failure, success } from '../utils/res' import { success, failure200 } from '../utils/res'
export function sendConfirmation({ chat, sender, msg_id }) { export function sendConfirmation({ chat, sender, msg_id }) {
if (!msg_id) return if (!msg_id) return
@ -135,7 +135,7 @@ let heartbeats:{[k:string]:boolean} = {}
export async function healthcheck(req, res) { export async function healthcheck(req, res) {
const pubkey: string = req.query.pubkey const pubkey: string = req.query.pubkey
if (!(pubkey && pubkey.length === 66)) { if (!(pubkey && pubkey.length === 66)) {
return failure(res, 'missing pubkey') return failure200(res, 'missing pubkey')
} }
const owner = await models.Contact.findOne({ where: { isOwner: true } }) const owner = await models.Contact.findOne({ where: { isOwner: true } })
@ -155,7 +155,7 @@ export async function healthcheck(req, res) {
try { try {
await network.signAndSend(opts) await network.signAndSend(opts)
} catch (e) { } catch (e) {
failure(res, e) failure200(res, e)
return return
} }
@ -164,7 +164,7 @@ export async function healthcheck(req, res) {
if (i >= 15) { if (i >= 15) {
clearInterval(interval) clearInterval(interval)
delete heartbeats[pubkey] delete heartbeats[pubkey]
failure(res, 'no confimration received') failure200(res, 'no confimration received')
return return
} }
if (heartbeats[pubkey]) { if (heartbeats[pubkey]) {

11
src/utils/res.ts

@ -16,4 +16,13 @@ function failure(res, e) {
res.end(); res.end();
} }
export {success, failure} function failure200(res, e) {
res.status(200);
res.json({
success: false,
error: (e&&e.message) || e,
});
res.end();
}
export {success, failure, failure200}
Loading…
Cancel
Save