mirror of
https://github.com/serverless/serverless.git
synced 2026-01-18 14:58:43 +00:00
30 lines
776 B
JavaScript
30 lines
776 B
JavaScript
'use strict';
|
|
|
|
const fetch = require('node-fetch');
|
|
const BbPromise = require('bluebird');
|
|
|
|
function localEmulatorRunning(localEmulatorRootUrl) {
|
|
const localEmulatorHeartbeatEndpoint = `${localEmulatorRootUrl}/v0/emulator/api/utils/heartbeat`;
|
|
const timestamp = (+new Date());
|
|
const payload = {
|
|
ping: timestamp,
|
|
};
|
|
|
|
return fetch(localEmulatorHeartbeatEndpoint, {
|
|
headers: {
|
|
'content-type': 'application/json',
|
|
},
|
|
method: 'POST',
|
|
timeout: 1000,
|
|
body: JSON.stringify(payload),
|
|
}).then(res => res.json())
|
|
.then(json => {
|
|
if (json.pong === timestamp) {
|
|
return BbPromise.resolve(true);
|
|
}
|
|
return BbPromise.resolve(false);
|
|
}).catch(() => BbPromise.resolve(false));
|
|
}
|
|
|
|
module.exports = localEmulatorRunning;
|