My Loki and Promtail server up and running. I want to send the log from my react js front end application. if try to post data it will give cors error. even i try to post ngnix proxy server also not working. how to achive that ?
const postLogsToLoki = async () => {
const lokiURL = 'http://localhost:3100/loki/api/v1/push'; // Replace with your Loki URL
const headers = {
'Content-Type': 'application/json',
// Add any other custom headers you need
'Access-Control-Allow-Origin':"*",
'Access-Control-Allow-Methods': 'GET, POST',
'Access-Control-Allow-Headers': 'Content-Type, Authorization'
};
const logData = {
streams: [
{
stream: {
lablename: 'test lable', // Replace with your labels
},
values: [
[new Date().toISOString(), 'post message from culture'],
// Add more log entries as needed
],
},
],
};
try {
const response = await axios.post(lokiURL, logData,{ headers }).catch((e)=>{
console.log(e);
});
console.log('Log posting successful:', response);
} catch (error) {
console.error('Error posting logs to Loki:', error);
}
};