@robotical/appv2-analytics-gatherer
Version:
A tool that gathers data from the Apps and sends it to the Analytics server
21 lines (20 loc) • 693 B
JavaScript
import { SERVER_URL } from "../config/config";
import Logger from "../services/Logger";
const SHOW_LOGS = true;
const TAG = 'transport/server';
export default class Transport {
static async post(endpoint, data) {
try {
Logger.info(SHOW_LOGS, TAG, `Posting to ${SERVER_URL}/${endpoint}`);
const response = await fetch(`${SERVER_URL}/${endpoint}`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(data)
});
return response;
}
catch (error) {
throw new Error(`Failed to post to ${endpoint}: ${error}`);
}
}
}