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.jstohttps://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
| Comment | File | Size | Author |
|---|---|---|---|
| nodejs socket.js issue.png | 504.16 KB | Syntapse |
Issue fork nodejs-3172690
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
Comment #2
Syntapse commentedtemporary 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
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
and added a proxy for socketio redirect:
i would be good to see proxy and socket.io configuration included in future releases.
Comment #4
imclean commentedThe
socket_ioconfiguration 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.Comment #6
imclean commentedComment #9
le72