Search code examples
apostropheapostrophe-cms

Why does apostrophe keep making POST calls to check if user logged in?


There are a bunch of POST calls from the website to the server and I don't know how to turn them off.

2019-10-24T21:24:49.606Z - info: admin already logged in. Passing through...
2019-10-24T21:25:09.767Z - info: /modules/apostrophe-notifications/poll-notifications
2019-10-24T21:25:09.768Z - info: admin already logged in. Passing through...
2019-10-24T21:25:29.911Z - info: /modules/apostrophe-notifications/poll-notifications
2019-10-24T21:25:29.912Z - info: admin already logged in. Passing through...
2019-10-24T21:25:50.023Z - info: /modules/apostrophe-notifications/poll-notifications
2019-10-24T21:25:50.024Z - info: admin already logged in. Passing through...

That just keeps going on and on...

In my app.js file, I've set the longPollingTimeout options to 0, but it doesn't stop it, and when I set it to 20000 ms it sends it every 20 seconds.

var apos = Mongo.getMongoPw().then(function(mongoPw){
  return require('apostrophe')({
    ...
    modules: {
      ...
      'apostrophe-notifications': {
        longPollingTimeout: 20000
      },
      ...
    }
  });

It seems very pointless and spammy in my logs which we send to splunk.

How can I turn this off if it's unnecessary?


Solution

  • The API you're referring to is polling for notifications, which can be sent at any time by server-side or browser-side code. For instance, if you try this in the browser console:

    apos.notify('Oh no!', { type: 'error' });
    

    You'll get a notification, which persists until dismissed (it's stored server-side).

    Where this gets more useful is when they are sent on the server side. For instance, your server-side javascript may also say:

    if (req.user) {
      // server side you must include req
      apos.notify(req, 'Oh no!', { type: 'error' });
    }
    

    Now a notification will reach the currently logged-in user, sooner or later, and you don't have to think about how to deliver it; it just gets taken care of for you by poll-notifications. This is very useful in long running tasks. Without this feature enabled Apostrophe would be unable to deliver many necessary messages to the user.

    However, you're wondering why you get this annoying message in your logs:

    admin already logged in. Passing through...

    I have checked both the apostrophe core module and the apostrophe workflow module. Neither contains any such message. I have also used github search to check the entire apostrophecms organization for this message, which does not appear. Same for a github-wide search. I left out the word "admin" and, in the apostrophecms org, also tried a search for "passing through" alone without turning up any code.

    So what this indicates is that your custom code, or another npm module you have added to your project, contains custom middleware that is logging this message on every request that comes in. I would recommend quieting that middleware down as it's not necessary to report this on every notification poll.