Skip to content

Commit f667b8c

Browse files
fix(api): allow POST requests without Content-Type header when body is empty
Previously, all POST requests required 'Content-Type: application/json' header, even when the request body was empty. This caused issues with endpoints like /api/monitor/ where parameters can be passed via URL instead of body. Now the Content-Type check is only enforced when a Content-Type header is actually provided, allowing empty-body POST requests to work correctly.
1 parent 20eff13 commit f667b8c

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

API/api.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,8 @@ module.exports = {
152152
}
153153
}
154154

155-
// Check for correct Content-Type header:
156-
if (req.method === "POST" && !req.is("application/json")) {
155+
// Check for correct Content-Type header (skip check if no content-type is set):
156+
if (req.method === "POST" && req.headers["content-type"] && !req.is("application/json")) {
157157
res.status(400).json({success: false, message: "Incorrect content-type, must be 'application/json'"});
158158
return;
159159
}

0 commit comments

Comments
 (0)