Unable to receive payload
rohinrohin opened this issue · 1 comments
const beaverLogger = require('beaver-logger/server');
const express = require('express');
// const bodyParser = require('body-parser');
const app = express();
// app.use(bodyParser.raw);
// app.use(bodyParser.json());
app.use(beaverLogger.expressEndpoint({
// URI to recieve logs at
uri: '/api/log',
// Enable cross-origin requests to your logging endpoint
enableCors: true
}));
This is my server code. The client init code is very similar to the demo code however I am passing the payload like so
$logger.error('hello_world', {
error: "somthing happened"
});
$logger.error('hello_world');
$logger.flush();
Whenever I try to log I only get an empty out with
[meta]
[track]
// or sometimes
[meta]
state: undefined
[track]
On further debugging I found that the request req.query
object is always empty. I am also unsure as to why you are checking for req.query in your handleRequest
method.
When I build my own endpoint for this logger I am able to get the data successfully like so:
{"events":[{"level":"error","event":"hello_world","payload":{"error":"somthing happened","timestamp":1500277459545,"windowID":"827a850fd2","pageID":"8d9532cb6b","client_elapsed":439078,"req_elapsed":440637}},{"level":"error","event":"hello_world","payload":{"timestamp":1500277459546,"windowID":"827a850fd2","pageID":"8d9532cb6b","client_elapsed":439079,"req_elapsed":440638}}],"meta":{"state":"ui_init"},"tracking":[]}
Since there is limited documentation on the same, I am unable to figure out why this is happening.
Note:
HTML file is locally served from the system (using file:// ....)
I was having the same issue til I realised you need to have body-parser
in place. If you uncomment those three lines from your server code it should work.