Hello,

Actually, I have done nodejs integration with Drupal 8 site.

I have integrated nodejs successfully with my site. But facing an issue with socket.io connection. I am facing the below error in the console:

"http://localhost:8080/socket.io/socket.io.js Failed to load resource: net::ERR_CONNECTION_REFUSE"

I have tried to find out the solution for this and not get the proper doc for this.

Please help me to fix this.

I have attached few files, that will help you to understand the things.

Below are the details:

1. node_modules location: In the root directory ==> /public_html

2. socket.io.js location: /public_html/node_modules/socket.io-client/dist

3. Code of nodejs.config.js:

settings = {
scheme: 'http',
port: 8080,
host: 'domainname.com',
resource: '/socket.io',
serviceKey: 'test',
backend: {
port: 8080,
host: 'domainname.com',
scheme: 'http',
basePath: '',
messagePath: '/nodejs/message'
},
debug: false,
sslKeyPath: '',
sslCertPath: '',
sslCAPath: '',
baseAuthPath: '/nodejs/',
extensions: [],
socketOptions: {}
};

4. For the Drupal backend configuration, I have added the screenshots. Please review.

Please let me know if need more details.

Thank you !!

Comments

jayesh_makwana created an issue. See original summary.

imclean’s picture

For general support you might have more luck on Drupal Answers: https://drupal.stackexchange.com/questions/tagged/nodejs

mashot7’s picture

Did you resolve that issue jayesh_makwana?

uniquename’s picture

StatusFileSize
new1.54 KB

I ran into the same problem and found out, that the url for socket.io comes from config/install/nodejs.config.yml, but for whatever reason it is not configurable via the settings form.

I created a quick patch to have those values configurable.

The file is meant to be loaded from the node app. So the url should point to it and it depends on your configuration. I work with ddev and have it exposed on port 3000, so my url is http://ddevd9.ddev.site:3000/socket.io/socket.io.js

imclean’s picture

imclean’s picture

imclean’s picture

The setting is already there it's just being ignored.

What I should've said is the socket_io config options don't need to exist. I think the file will always be served by nodejs so a separate setting isn't required.

globexplorer’s picture

Hi guys,

I confirm this issue. The reason for that is, that the config form does not show all options possible. If you look in into the config/install folder you will recognize the following data:

service_key: '__FIXME__'
log_http_errors: true
auth_get_token_callback: 'nodejs_auth_get_token_callback'
auth_check_callback: 'nodejs_auth_check_callback'
enable_userchannel: true
pages: '*'
authenticated_users_only: false
nodejs:
  scheme: 'http'
  host: 'localhost'
  port: 8080
client:
  scheme: 'http'
  host: 'localhost'
  port: 8080
socket_io:
  path: 'http://localhost:8080/socket.io/socket.io.js'
  type: 'external'

But the config form does not show a field referring to that data socket_io. The next function is checking the config, and of course will find it, and therefore always shows the hardcoded value from the config!

/**
 * Return the path to the socket.io client js.
 */
function nodejs_get_socketio_js_config($nodejs_config) {
  $socket_io_config = \Drupal::config('nodejs.config')->get('socket_io');
  if (!$socket_io_config['path']) {
    $socket_io_config['path'] = $nodejs_config['client']['scheme'] . '://' . $nodejs_config['client']['host'] . ':'
                              . $nodejs_config['client']['port'] . '/socket.io/socket.io.js';
  }
  return $socket_io_config;
}