totaljs / framework

Node.js framework
http://www.totaljs.com
Other
4.36k stars 450 forks source link

Endpoint called up to 4 times #582

Closed gmenih closed 6 years ago

gmenih commented 6 years ago

I recently started working on a project written in TotalJS.

I seem to have a weird issue, where an API call will call the endpoint up to 4 times. Here's how I call the endpoint:

$.components.GET('/api/endpoint/', options, function (response) {
    console.log(response);
});

The endpoint handler is pretty simple, it basically does this:

GETSCHEMA('Product').query(self.query, self.callback);

However, this gets called anywhere from 1 to 4 times. And the stack trace is always the same:

at endpoint_handler (/home/grega/Projects/Work/totaljs_project/controllers/manager.js:1675:10)
at PROTO.$total_execute2 (/home/grega/Projects/Work/totaljs_project/node_modules/total.js/index.js:13944:31)
at PROTO.$total_execute (/home/grega/Projects/Work/totaljs_project/node_modules/total.js/index.js:13914:8)
at PROTO.$total_authorize (/home/grega/Projects/Work/totaljs_project/node_modules/total.js/index.js:14032:9)
at (anonymous) (/home/grega/Projects/Work/totaljs_project/node_modules/total.js/index.js:14195:8)
at F.onAuthorize (/home/grega/Projects/Work/totaljs_project/models/users.js:201:2)
at PROTO.$total_prepare (/home/grega/Projects/Work/totaljs_project/node_modules/total.js/index.js:14186:5)
at PROTO.$total_end (/home/grega/Projects/Work/totaljs_project/node_modules/total.js/index.js:13855:8)
at F.$requestcontinue (/home/grega/Projects/Work/totaljs_project/node_modules/total.js/index.js:6984:8)
at F.listener (/home/grega/Projects/Work/totaljs_project/node_modules/total.js/index.js:6833:4)
at emitTwo (events.js:135:12)
at emit (events.js:224:6)
at parserOnIncoming (_http_server.js:619:11)
at parserOnHeadersComplete (_http_common.js:117:22)
petersirka commented 6 years ago

Hi @gmenih341, can I see the code on this line /manager.js:1675:10?

Which version of Total.js + jComponent do you use? BTW: instead of $.components.GET() use AJAX('GET /api/endpoint/', options, function(response) {.

Thank you!

gmenih commented 6 years ago

@petersirka The line 1675:10 is just console.trace(), and just below it there's the GETSCHEMA line I pasted above.

TotalJS version is 2.9.0, and I can't find jComponent being explicitly installed.

petersirka commented 6 years ago

@gmenih341 please write me the whole exception.

gmenih commented 6 years ago

There's no exception. It just calls the endpoint handler 4 times, and I get 408 status code on my api calls because of it.

petersirka commented 6 years ago

But before the line below is something: at endpoint_handler (/home/grega/Projects/Work/totaljs_project/controllers/manager.js:1675:10)

And I need to see it and send me the content .setQuery() of Product schema.

petersirka commented 6 years ago

I'm going to travel, so I will back around 3 hours.

molda commented 6 years ago

You are missing parenthesis after self.callback

GETSCHEMA('Product').query(self.query, self.callback());

self.callback needs to be called because it returns a function depending on content type, so for json it will use self.json and for view self.view

gmenih commented 6 years ago

@molda ah, thanks for that info. I thought there was an error in code, so I actually removed the parenthesis. This, however, still doesn't solve my issue :/

molda commented 6 years ago

Try to replace self.callback() with a function:

GETSCHEMA('Product').query(self.query, function (err, response) {
    console.log(err, response);
    self.json(response);
});

Do you see the results in the console?

gmenih commented 6 years ago

Yep, I see the console.log being called multiple times.

molda commented 6 years ago

Can you show us your controller??

petersirka commented 6 years ago

Is there any news?