I am new to loopback.
I am trying to add a remoteMethod 'greet' to model user (based on User)
// common/models/user.json
{
"name": "user",
"plural": "users",
"base": "User",
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {},
"validations": [],
"relations": {
"tweets": {
"type": "hasMany",
"model": "tweet",
"foreignKey": "ownerId"
}
},
"acls": [],
"methods": {}
}
// common/models/user.js
module.exports = function(User) {
User.greet = function(msg, cb ) {
cb(null, 'Greetings... ' + msg);
};
User.remoteMethod(
'greet',
{
accepts: {arg: 'msg', type: 'string'},
returns: {arg: 'greeting', type: 'string'}
}
);
};
The greet method shows up in the explorer but if i try a POST request to it, I get:
"message": "Shared class \"User\" has no method handling POST /greet?access_token=EQTxhBsZvVSNaxxsWdN3Mq6MgvBhYWZdD7k1raeV2BAlsOEb6kYYRMuvOtTg7tvW",
"statusCode": 404,
But if I add the same method to a model based on PersistedModel, it works. Why?