Reputation: 2523
So I added an http-mock for users that returns just a single user on the get route like so...
usersRouter.get('/:id', function(req, res) {
res.send({
"users": {
"id": 1,
"pin": 1234,
"first_name": "John",
"last_name": "Doe",
"email": "[email protected]",
"phone": 8436376960
}
});
});
In my model I have this
import DS from 'ember-data';
export default DS.Model.extend({
pin: DS.attr('number'),
first_name: DS.attr('string'),
last_name: DS.attr('string'),
email: DS.attr('string'),
phone: DS.attr('number')
});
and in my action when I submit a form I have this to perform the get request
return this.store.find('user',id);
when I click on the submit button I see in the console a 404 error to the get url like so
GET http://localhost:4200/users/1 404 (Not Found)
do I need to do anything else to get this mock to work? I didn't see anything about needing an adapter or serializer to get the mock to work
Upvotes: 1
Views: 393
Reputation: 2523
I noticed when generating an http-mock in ember-cli the express app code states
app.use('/api/users', usersRouter);
and ember was just looking at /users/:id
so I simple generated an application adapter, rest was fine here, and set the namespace like so
import DS from 'ember-data';
export default DS.RESTAdapter.extend({
'namespace': 'api'
});
I decided to go with this approach as apposed to removing the api url endpoint from the app.use because future http-mocks will use the api endpoint in their app.use and I thought it best for future generation of http-mocks to just create an adapter.
Upvotes: 3