Search code examples
serverhttp-status-code-404fetchloopback

receiving a 404 error when I make a post request to api server


I've created a custom endpoint for my api server which deletes a single hearing test:

Account.deleteSingleHearingTest = function (req, callback) {
        // console.log('accounts.js: deleteSingleHearingTest: are we being reached????', req)
        Account.findById(req.accessToken.userId)
            .then(account => {
                if (!account) {
                    throw new Error('Cannot find user');
                }
                console.log('account.js: deleteSingleHearingTest: req.body.hearingTestId    N: ', req.body.hearingTestId);
                return app.models.HearingTest.updateAll({ accountId: account.id, id: req.body.hearingTestId }, { isDeleted: new Date() });

            })
            .then(() => {
                callback(null);
            })
            .catch(error => {
                callback(error);
            });
    }

    Account.remoteMethod(
        'deleteSingleHearingTest', {
            http: {
                path: '/deleteSingleHearingTest',
                verb: 'post'
            },
            accepts: [
                { arg: 'req', type: 'object', description: 'removes a single hearing test', http: { source: 'req' } }
            ],
            description: 'this is the end point for a single delete',
            returns: {}
        }
    );

I've also updated acls in account.json:

{
      "accessType": "EXECUTE",
      "principalType": "ROLE",
      "principalId": "$authenticated",
      "permission": "ALLOW",
      "property": "deleteSingleHearingTest"
    }

Using Postman, I made a POST request to the server address which looks something like :

https://xxx.xxxxxxxx.com/api/Accounts/deleteSingleHearingTest?access_token=XXXXXXXXXXXXXXXXXKyBdxkwxm5s8TSceMgclvXjjrTnyn3UJWIa

The response I get back on Postman is a 404 with the attached message

"Shared class \"Account\" has no method handling POST /deleteSingleHearingTest?access_token=XXXXXXXXXXXXXXXXXXqAoKyBdxkwxm5s8TSceMgclvXjjrTnyn3UJWIa",

The strange thing is, this method was working two weeks ago when I first created, the only difference was that I was running the server locally.


Solution

  • I needed to restart the server so the new methods could be pulled in. For the 1 person who actually reads this. To restart the server the command is pm2 start all