fix: resolve JSON.parse error in frontend API calls

- Add error handling for JSON encoding in all backend handlers
- Add CORS support to backend server
- Add proxy configuration for frontend development server
- Improve error handling in frontend API calls
- Build frontend to create static files for backend serving
- Add comprehensive error messages and user feedback

Fixes issue where frontend received malformed JSON responses from backend API.
This commit is contained in:
2026-02-05 20:14:12 -05:00
parent 551ae1890d
commit c9003a208a
11 changed files with 238 additions and 23 deletions

28
backend/test/test_api.sh Executable file
View File

@@ -0,0 +1,28 @@
#!/nix/store/ypgcdmzzlgnrmdcsq72c3dxz651jg9zc-bash-5.3p3/bin/bash
# Start the server in the background
./markdown-editor --data-dir ./test/data --port 8081 --host 127.0.0.1 &
SERVER_PID=$!
# Give the server time to start
sleep 2
# Test the /api/files endpoint
echo "Testing GET /api/files..."
response=$(curl -s http://127.0.0.1:8081/api/files)
echo "Response: $response"
echo ""
# Test if it's valid JSON
if echo "$response" | python3 -m json.tool > /dev/null 2>&1; then
echo "✓ Response is valid JSON"
else
echo "✗ Response is NOT valid JSON"
echo "Response was: $response"
fi
# Kill the server
kill $SERVER_PID 2>/dev/null
wait $SERVER_PID 2>/dev/null
echo "Test completed"