Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cdfc31a
commit d2665aa
Showing
2 changed files
with
75 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
const request = require('request') | ||
const urljoin = require('url-join') | ||
|
||
const push = ({ table, name, address, value }) => { | ||
return new Promise(async (resolve, reject) => { | ||
let url = urljoin(`https://metrics.tomochain.com`, 'write', '?db=tomobridge') | ||
let data = ` | ||
${table},name=${name},address=${address} value=${value} | ||
` | ||
let options = { | ||
method: 'POST', | ||
url: url, | ||
encoding: null, | ||
body: Buffer.from(data, 'utf-8') | ||
} | ||
request(options, (error, response, body) => { | ||
if (error) { | ||
return reject(error) | ||
} | ||
if (response.statusCode !== 200 && response.statusCode !== 201) { | ||
return reject(body) | ||
} | ||
|
||
return resolve(body) | ||
}) | ||
|
||
}) | ||
} | ||
|
||
module.exports = { | ||
push | ||
} |
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