Skip to content

Commit 264bbe8

Browse files
committed
fix: Accept empty POST requests
1 parent 6863460 commit 264bbe8

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

packages/micro-analytics-cli/src/handler.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const url = require('url');
2-
const { json, send, createError, sendError } = require('micro');
2+
const { json, text, send, createError, sendError } = require('micro');
33

44
const db = require('./db');
55
const healthcheckHandler = require('./healthcheck');
@@ -25,7 +25,10 @@ function realtimeHandler(req, res) {
2525
}
2626

2727
async function readMeta(req) {
28-
return (await json(req)).meta;
28+
if (await text(req)) {
29+
return (await json(req)).meta;
30+
}
31+
return null;
2932
}
3033

3134
async function analyticsHandler(req, res) {
@@ -62,8 +65,11 @@ async function analyticsHandler(req, res) {
6265
}
6366
const shouldIncrement = String(query.inc) !== 'false';
6467
try {
68+
let meta;
6569
const currentViews = (await db.has(pathname)) ? (await db.get(pathname)).views.length : 0;
66-
const meta = await readMeta(req);
70+
if (req.method === 'POST') {
71+
meta = await readMeta(req);
72+
}
6773

6874
const data = { time: Date.now() };
6975
if (meta) {

0 commit comments

Comments
 (0)