MacroPower / macropower-analytics-panel

It's like Google Analytics, but for Grafana dashboards!
https://grafana.com/grafana/plugins/macropower-analytics-panel
GNU General Public License v2.0
27 stars 7 forks source link

SyntaxError: JSON.parse: unexpected end of data at line 1 column 1 of the JSON data #10

Closed jtommi closed 4 years ago

jtommi commented 4 years ago

I threw together a quick listener using nodejs, but when activating "Post end", I get an error saying it couldn't parse the response and I don't understand why.

As you see, the payload looks good in Firefox and the Content type is JSON image

Here is the NodeJS snippet:

app.post('/load', (req, res) => {
  res.statusCode = 201;
  res.json({ location: '12345664' });
  res.end();
});

I'm using a fresh docker image of Grafana 7.1.5

MacroPower commented 4 years ago

Hello there, a similar problem was mentioned in #4 and the origin was a problem with the CORS configuration.

If that doesn't help, can you please post a screenshot of the issue + the settings you're using?

jtommi commented 4 years ago

I'm sorry, there were 8 total issues on this project and I missed the one that exactly described my issue. Obviously, I follow the instructions and it works fine.

It might be an idea to modify the panel settings to prevent this. Have a "source" setting where you can choose between Telegraf and Custom. If you choose custom, the CORS option disappears, etc. I'm currently learning Javascript, so I might actually look into how that can be done. Another idea I have in mind is a "keep-alive" option: since the plugin can't send the end request when the browser window is closed, it could send a keep alive to the server every x minutes. The server could than be configured to consider a session ended if it didn't receive a keep-alive for more than x+1 minutes (or more) which could still be overwritten if the end request comes in.