Grunt - SoftwareSandbox/FiAngulartje GitHub Wiki
Caution with cached locally served .json
When you're testing a resource, keep in mind that the local server that Grunt starts with grunt serve has a cache implementation so that when your Angular app requests the same url a second time it can serve the cached response.
I had a /api/v1/categories/1.json
file I was serving which before I did grunt serve
contained [{id:...}]
. A 1 element array of the category with id 1.
I changed this to not return an array because it's a GET by an id and should only return a single object, not an array. So I removed the [] in the 1.json
file.
When I was checking out how $resource worked at some point it started throwing exceptions that said "expected object, but got an array".
In my Chrome Developer Tools pane I could check the network tab to see what requests and responses were being exchanged. And indeed, on a GET to http://localhost:9000/api/v1/categories/1 the response returned a [{id:...}]
. Still an array, eventhough my file did not contain the [] brackets. I did notice though that it wasn't a regular 200 ok that got returned with that request, but a 304 not modified. Which means I got a cached version.
After I restarted the server with grunt serve
, it finally worked.
Took me a fair amount of time to figure that one out.
Lesson learned
check network pane sooner rather than later.