TypeError: sw[("add" + method)] is not a function when starting server

2 views
Skip to first unread message

Paul Carron

unread,
Sep 5, 2018, 2:14:46 AM9/5/18
to restify
I'm not sure if it's a restify issue but thought I'd ask just in case.

I created a Node.js rest api. It follows the general controller, model, schema structure and uses a restify server which I start by running node index.js.


The controller consists of a controllers/baseController.js which contains some operations relevant to all of my controller classes. My controllers/issues.js which extends controllers/baseController.js initially only had a GET, POST and PUT operations. Whilst not complete, these worked fine. They certainly didnt prevent the server fron starting.


I then added the following delete action to my controller:


controller.addAction({ 'path': '/issues', 'method': 'DELETE', 'summary': 'Delete all issues from the list', 'responseClass': 'Issues', 'nickname': 'deleteIssues' }, controller.delete);

It routes to: delete(req, res, next) {
 let collectionContents
= this.lib.db.model('Issues');
 collectionContents
.remove({}, (err, result) => {
 
if(err) return next(this.RESTError('InternalServerError', err));
 
this.writeHAL(res, result);
 
});
}



However, when I try to start my server I get this error:


MBP:issue-tracker pac$ node index.js
2018-09-04T13:41:52.618Z [Default] info: Setting up auto-doc for ( GET ) - getIssues
2018-09-04T13:41:52.624Z [Default] info: Setting up auto-doc for ( DELETE ) - deleteIssues
/Users/pac/git/issue-tracker/controllers/baseController.js:19
      app[method.toLowerCase()](act['spec']['path'], act['action']);
                           ^

TypeError: app[method.toLowerCase(...)] is not a function
    at actions.forEach.act (/Users/pac/git/issue-tracker/controllers/baseController.js:19:32)
    at Array.forEach (<anonymous>)
    at Issues.setUpActions (/Users/pac/git/issue-tracker/controllers/baseController.js:15:18)
    at Object.setupRoutes (/Users/pac/git/issue-tracker/lib/helpers.js:13:12)
    at Object.<anonymous> (/Users/pac/git/issue-tracker/index.js:35:13)
    at Module._compile (module.js:635:30)
    at Object.Module._extensions..js (module.js:646:10)
    at Module.load (module.js:554:32)
    at tryModuleLoad (module.js:497:12)
    at Function.Module._load (module.js:489:3)
    at Function.Module.runMain (module.js:676:10)
    at startup (bootstrap_node.js:187:16)
    at bootstrap_node.js:608:3

baseController.js is here.


It seems to have an issue with 'method': 'DELETE'. However, I can't figure out why. I thought it may be Swagger related as I believe the functions such as addGET, addPOST etc are there and that maybe addDELETE doesn't exist but I checked and it's there. I also read somewhere that Restify uses DEL rather than DELETE but I tried that and still get the issue. Can anybody explain what might be wrong here?

Reply all
Reply to author
Forward
0 new messages