Problem/Motivation

I think this issue may resolve this issue: https://www.drupal.org/project/nodejs/issues/3172629

I am running a drupal site and node.js server behind an nginx reverse proxy. the issue above details all the steps i have tried without success to get broadcast notifications working.

I think the cause may be a hard coded reference to http://localhost:8080/socket.io/socket.io.js resulting in an net::ERR_CONNECTION_REFUSED error in the browser.

I tried overriding the locatoin of socket.io.js in module\contrib\nodejs\config\install\nodejs.config.yml with the cdn version (https://cdn.jsdelivr.net/npm/socket.io-client@2/dist/socket.io.js) and cleared the cache but the loaded asset didnt change and the problem persists so it appears that drupal is not reading it from this file but i cant work out where it is reading it from if not here. I tried changing the value of the socket io path in the drupal module yml file to use a cdn version to avoid having to configure nginx to deliver it but that didnt work.

e.g. node.js.config.yml

  service_key: '__FIXME__'
  log_http_errors: true
  ...
  ...
  socket_io:
    path: 'https://cdn.jsdelivr.net/npm/socket.io-client@2/dist/socket.io.js'
    type: 'external'

The location of socket.io.js is not configurable from the UI so i dont know how to change it if not in this file. Im unsure if it will fix my connection problems entirely but I need to clear this error and correctly load socket.io.js to make progress.

Steps to reproduce

  • See the attached pictures.
  • Start with an error free browser.
  • Install nodejs integration and sub-modules
  • note ERR_CONNECTION_FAILED browser error.
  • change configuration at /admin/config/nodejs/settings
  • note absence of UI configuration for socket.io.js
  • reload any drupal page. note persistence of the connection error
  • change the socket io path from http://localhost:8080/socket.io/socket.io.js to https://cdn.jsdelivr.net/npm/socket.io-client@2/dist/socket.io.js
  • start the node.js server with debug enabled
  • run two drupal sessions and broadcast messages from each
  • note that communication between drupal backend and node.js server is working i,e. messages are being logged
  • note that there are no notifications in the browser

Proposed resolution

Looking at the defaults it looks like node.js integration is set up to work on localhost by default which wont apply in most real world applications. It would be great to have some documentation and advice how to configure correctly node.js for proxied setups.

Remaining tasks

User interface changes

API changes

Data model changes

CommentFileSizeAuthor
nodejs socket.js issue.png504.16 KBSyntapse

Issue fork nodejs-3172690

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

Syntapse created an issue. See original summary.

Syntapse’s picture

temporary workaround:

i made a few changes to get sockets routing properly. i havent been able to work out how to override module\contrib\nodejs\config\install\nodejs.config.yml so i included a cdn version in libraries.yml

modules\_data\contrib\nodejs\nodejs_ajax\nodejs_ajax.libraries.yml

  https://cdn.jsdelivr.net/npm/socket.io-client@2/dist/socket.io.js: { type: external }

also had to remove requirement for a client port as this was breaking my routing. in a proxied setup a port is not always required.

modules\_data\contrib\nodejs\src\Form\NodejsConfigForm.php

    $form['server']['client_port'] = array(
      '#type' => 'textfield',
      '#title' => $this->t('Node.js server port for client javacript'),
      '#default_value' => $config->get('client.port'),
      '#size' => 10,
      // '#required' => TRUE,
      '#description' => $this->t('The port of the Node.js server.'),
    );

and added a proxy for socketio redirect:

  # node.js integration proxy redirect
  location ^~ /socket.io {
      proxy_pass http://0.0.0.0:8080/socket.io;
      proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection 'upgrade';
      proxy_set_header Host $host;
      proxy_cache_bypass $http_upgrade;
  }

i would be good to see proxy and socket.io configuration included in future releases.

imclean made their first commit to this issue’s fork.

imclean’s picture

The socket_io configuration can't be set on the config screen so it always uses the default socket.io path. This change makes sure the socket.io path is always constructed by the nodejs module settings.

imclean’s picture

Status: Active » Needs review

le72 made their first commit to this issue’s fork.

  • le72 committed b2d2959 on 8.x-1.x authored by imclean
    Issue #3172690 by imclean, le72, Syntapse: preconfigured socket.io...
le72’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.