EventSubscriber called on specific node type or path I'm trying to set an event that will launch function that loads some data from outside server and print it to javascript div element. I tried many ways but I can't figure out how to make this event be called only on for a specific node type.

Code I got so far:

class eSubscriber implements EventSubscriberInterface {

  public static function getSubscribedEvents() {
    $events[KernelEvents::RESPONSE][] = ['onRespond',27]; //so far it works on respond but on every page
    return $events;
  }

  public function onRespond(FilterResponseEvent $event) {
    //do some stuff
  }

}
I managed to do it but I feel it could be done much better.

class eSubscriber implements EventSubscriberInterface {

  public static function getSubscribedEvents() {
    $events[KernelEvents::TERMINATE][] = ['onRespond',27];
    return $events;
  }

  public function onRespond(PostResponseEvent $event) {
    $node = \Drupal::routeMatch()-&gt;getParameter('node');
    $user = \Drupal::currentUser();
    $name = $user-&gt;getUsername();

    $output = [];
    if (isset($node) &amp;&amp; isset($name)) {

      $nodeType = $node-&gt;getType();
      $soap_response = new classThatHandleRequests();
      $output = $soap_response -&gt; get_clients_fv($name);
      echo('&lt;script&gt;var JSONarray = ' . print_r($output,1) . ';&lt;/script&gt;');
    }
  }
}