Files
cgm-remote-monitor/lib/api
Ben West 636ef4091b Fix entries API POST response format and empty array handling
Fixes two bugs in the entries API that caused test failures:

1. POST endpoints now return JSON arrays consistently
   - Created format_post_response() middleware for POST requests
   - Replaces format_entries() which is designed for GET with content negotiation
   - Previously, POST requests without Accept header defaulted to text/plain handler
   - This caused responses to fail or return empty objects instead of JSON arrays
   - Now matches behavior of treatments and devicestatus APIs

2. Fixed callback never being called for empty array posts
   - Added empty array check in lib/server/entries.js create() function
   - Previously, empty array caused forEach loop to never execute
   - Completion callback was inside forEach, so never triggered for empty input
   - This caused 15 second timeouts on POST requests with empty arrays

All 26 tests in api.shape-handling.test.js now pass.

Files changed:
- lib/api/entries/index.js: Added format_post_response, updated POST routes
- lib/server/entries.js: Added empty array handling in create()
2026-01-19 13:14:21 -08:00
..
2023-01-01 13:05:17 +02:00
2021-10-25 20:13:40 +03:00
2020-12-11 00:23:25 +02:00