UNPKG

monitor-nodejs

Version:
34 lines (26 loc) 697 B
'use strict' const axios = require('axios') class Handler { constructor(options = {}) { this.options = options } async handle() { throw new Error('Handler not implemented') } } class AxiosHandler extends Handler { async handle(entries) { const headers = { 'Content-Type': 'application/json', 'Accept': 'application/json', 'X-Monitor-Key': this.options.ingestionKey, 'X-Monitor-Version': this.options.version, } const transformed = entries.map(entry => entry.transform()) await axios.post(this.options.url, { entries: transformed }, { headers }) } } module.exports = { Handler, AxiosHandler, }