loopback icon indicating copy to clipboard operation
loopback copied to clipboard

Remote method not invoked when model name is one of the following: Ad, Advert, Advertisement

Open itbitescode opened this issue 9 years ago • 2 comments

Description/Steps to reproduce

Here's is a very peculiar issue I've came accross today. I must say that I'm very new to Loopback, but the case seems so trivial I would never expect it to take me so much time to resolve.

I have followed https://loopback.io/doc/en/lb3/Extend-your-API.html to extend my model called Ad.

Here is the content of ad.js file (in common/models directory)

'use strict';

module.exports = function(Ad) {
  Ad.status = function (cb) {
    console.log('Status invoked');
    cb(null, "Status responded!");
  };
  Ad.remoteMethod(
    'status', {
      http: {
        path: '/status',
        verb: 'get'
      },
      returns: {
        arg: 'status',
        type: 'string'
      }
    }
  );
};

And here is ad.json

{
  "name": "Ad",
  "base": "PersistedModel",
  "idInjection": true,
  "options": {
    "validateUpsert": true
  },
  "properties": {
    "name": {
      "type": "string",
      "required": true
    }
  },
  "validations": [],
  "relations": {},
  "acls": [],
  "methods": {}
}

model-config has such definition (however I've noticed it has no impact on the result):

"Ad": {
    "dataSource": "mongods",
    "public": true
  }

I'm running the whole think in docker (though, it shouldn't matter) and it's basically an autogenerated code (I've just started the project).

I opened the API explorer and the status method is available indeed.

Now the fun part begins.

Opening to the API explorer I expected to see a proper response after invoking the status method. But instead, I saw this:

Curl

curl -X GET --header 'Accept: application/json' 'http://localhost:3000/api/Ads/status'

Request URL

http://localhost:3000/api/Ads/status

Response Body

no content

Response Code

0

Response Headers

{ "error": "no response from server" }

To spice things up a little it turned out that there is no output it the console log. And I expected the console to display:

Status invoked

Naturally I started looking for things like: method overwrites (I suspected there is already a 'status' method declared and it clashes with the remote method for some reason). Then I though maybe it's something with the logging. I tested it and logging works fine everywhere else in the app.

So, I renamed the file (and each occurance of Ad) to Advice... Guess what? It worked as expected! ... So, I thought, maybe the file name is too short (?). I renamed everything to Advert and it stopped working again. Checked Advertisement only to see exactly the same results :D

I veryfied that names like Offer, Dashboard, Adrian work fine.

Any idea what that could be? I'm pretty attached to naming my model Ad (since that's what it is ;) ). Is it some sort of easter egg? ;)

itbitescode avatar Jun 08 '17 11:06 itbitescode

@itbitescode You might want to try "mysqlDs" or "db" instead?

"Ad": { "dataSource": "mysqlDs", "public": true }

What do you see in server/boot/datasources.json? By default, the getting-started app has "db" and "mysqlDs" set up.

Setogit avatar Jun 13 '17 17:06 Setogit

Please submit a new issue if needed. closing one month or older issues. thanks!

Setogit avatar Jul 21 '17 20:07 Setogit