GET /simpleads/impression/NNN: Method Not Allowed

Created on 11 July 2024, 4 months ago

Problem/Motivation

I'm seeing "client error" type errors in watchdog on every page load (Drupal 10.2.7, SimpleAds 2.0.10):

Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException: No route found for "GET https://www.xxxxxx.xxx/simpleads/impression/7": Method Not Allowed (Allow: POST) in Symfony\Component\HttpKernel\EventListener\RouterListener->onKernelRequest() (line 131 of /home/xxxxxxx/public_html/vendor/symfony/http-kernel/EventListener/RouterListener.php).

The string "simpleads/impression" appears twice in src/Plugin/rest/resource/SimpleAdsImpressions.php and once in js/simpleads.lib.js.

In the latter, I found that the error stops if I disable the trackImpression function, but of course that's not a good thing to do:

  /**
   * Track impressions private method.
   */
  function trackImpression(entity_id) {
//    requestCsrf('simpleads/impression/' + entity_id);
  };

My javascript expertise is minimal so I wasn't able to get any further with this. I did try adding "method: 'POST'," to the first jQuery.ajax call here, but it didn't seem to fix anything:

  /**
   * Get CSRF token before making POST request.
   */
  function requestCsrf(endpoint, callback) {
    jQuery.ajax({
      method: 'POST',
      url: getDomainWithPort() + 'session/token',
    })
    .done(function(csrf) {
      jQuery.ajax({
        type: 'post',
        url: drupalSettings.path.baseUrl + endpoint + '?_format=json',
        headers: {
          'X-CSRF-Token': csrf,
          'Content-Type': 'application/json'
        }
      });
    });
  };

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Active

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States rclemings

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024