I was getting "Unexpected token ILLEGAL" so I added output of the 'chunk' variable on server.js line 289, and it's borking on an HTML 404 page. (Each line comes through as a chunk and fails to parse as JSON.)
I'm not that familiar yet with node.js or with websockets, but presumably I have something configured wrong. I seem to have the server running on 8080, but how do I debug the pages the websocket is trying to reach?

More generally, what are the modules in the package supposed to do when they're all turned on and the node.js server is running?

(I'm at DrupalCon now, I attended both node.js BoFs, so if one of the maintainers could spare a few minutes, it would be awesome)

Thanks

Comments

thebuckst0p’s picture

I think I found the problem, my site was running on a subdirectory but my paths in nodejs.config.js were relative to the root.
Would it be possible to put some more detailed documentation in the README on how to use the config file?

Thanks for the great work on this!

arithmetric’s picture

Version: 7.x-1.0-alpha2 » 7.x-1.0-alpha3
Status: Active » Fixed

I've added more details to nodejs.config.js.example for how the configuration options are used. At this point, this change is in the git repository only.

tuongaz’s picture

I stil got this error. Below is my nodejs.config.js:

drupalSettings = {
  'host': '127.0.0.1',
  'port': 8080,
  'resource': '/node.js/realtime',
  'publishUrl' : '/publish',
  'backend': {
    'port': 80,
    'host': 'localhost',
    'authPath': '/nodejs/auth/'
   }
}

Any suggestions?

My Drupal site is: http://dev.drupal7

arithmetric’s picture

Try setting the first "host" under drupalSettings to an empty string ('').

If you have host set to 127.0.0.1, then the node server will only listen for connections from clients to that IP address. Unless clients are coming from the same system (localhost), then they'll be using a different IP address (i.e. 192.168.0.60 on your private LAN).

Also, for the "host" value under backend: If you're using "localhost", then make sure that your Drupal site responds to this host name (rather than another name, like dev.drupal7 as you mentioned).

tuongaz’s picture

Thanks
Just did as you suggested but still got the following error:

17 Mar 10:31:14 - socket.io ready - accepting connections
17 Mar 10:31:41 - Initializing client with transport "websocket"
17 Mar 10:31:41 - Client 8910823604092002 connected
Failed to parse authentication message: SyntaxError: Unexpected token ILLEGAL

and here's the config file as per ur suggestion:

drupalSettings = {
  'host': '',
  'port': 8080,
  'resource': '/node.js/realtime',
  'publishUrl' : '/publish',
  'backend': {
    'port': 80,
    'host': '',
    'authPath': '/nodejs/auth/'
   }
}
Anonymous’s picture

what that log message says:

1. the drupal webpage was loaded successfully in the browser
2. the socket.io js ran, and successfully opened a connection to node.js
3. node.js then tried to authenticate the client via drupal, and got something back that wasn't valid JSON

the request from node.js ---> drupal uses backend.host to set the host for the http auth request.

using '' for the host won't work, it needs to be set to the hostname the drupal site runs as, and the node.js process needs to be able to resolve that hostname.

arithmetric’s picture

Yes, I was only suggesting to leave the first host parameter empty. The second host parameter needs to be the host that the node.js server process uses to contact the Drupal site.

The fact that a client connected is a good sign.

I'd suggest something like:

drupalSettings = {
  'host': '',
  'port': 8080,
  'resource': '/node.js/realtime',
  'publishUrl' : '/publish',
  'backend': {
    'port': 80,
    'host': 'dev.drupal7',
    'authPath': '/nodejs/auth/'
   }
}
ifuyivara’s picture

I'm getting the same error. My drupal instalation is in a directory on localhost. (localhost/drupal)
My settings:

drupalSettings = {
  'host': '',
  'port': 8080,
  'resource': '/node.js/realtime',
  'publishUrl' : '/publish',
  'backend': {
    'port': 80,
    'host': 'localhost',
    'authPath': '/nodejs/auth/'
   }
}

Are those settings correct?

afeijo’s picture

no, your authPath should be /drupal/nodejs/auth/

tuongaz’s picture

Thanks guys.

I installed a fresh D7 + Nodejs and now all working well.

logii’s picture

I'm so near but yet so far..

I installed socket.io with NPM and also downloaded from https://github.com/learnboost/socket.io-node
Renamed the folder to socket_io and uploaded to /sites/all/modules/nodejs/socket_io
After running $ node server.js , I get the error below

  $ node [drupal-root]/sites/all/modules/nodejs/server.js
  30 Mar 17:56:08 - Your node instance does not have root privileges. This means that the flash XML policy file will be served inline instead of on port 843. This will slow down initial connections slightly.
  30 Mar 17:56:08 - socket.io ready - accepting connections
  
  30 Mar 17:56:14 - Client 7213927619159222 connected
  Failed to parse authentication message: SyntaxError: Unexpected token ILLEGAL
  30 Mar 17:56:25 - Client 7213927619159222 disconnected
  30 Mar 17:56:25 - Couldnt find client with session id "7213927619159222"
  30 Mar 17:56:25 - Couldnt find client with session id "7213927619159222"
  30 Mar 17:56:28 - Initializing client with transport "xhr-multipart"
  30 Mar 17:56:28 - Client 5646870869677514 connected
  Failed to parse authentication message: SyntaxError: Unexpected token ILLEGAL

My nodejs.config.js

backendSettings = {
  'scheme': 'http',
  'host': '',
  'port': 8080,
  'resource': '/node.js/realtime',
  'publishUrl': '/publish',
  'backend': {
    'port': 8080,
    'host': 'nodejs.mydomain.com',
    'authPath': '/home/user/[drupal-root]/nodejs/auth/'
   }
};

Is there anything wrong with my config file?

ps: Thanks for integrating node.js as API in Drupal. Now Drupal development has become sexy!

Cheers,
Logi

logii’s picture

Version: 7.x-1.0-alpha3 » 7.x-1.0-alpha4
Status: Fixed » Active
afeijo’s picture

the authPath is not relative to your linux structure, but to your websocket in port 8080

In another issue it has been mentioned that if you have your drupal in a folder instead the www root, you need to add the folder name to authPath, try it:

'authPath': '/foldername/nodejs/auth/'

arithmetric’s picture

Also, the port under "backend" should not be the same as the first port. The "backend" port refers to the HTTP port that your Drupal site is running on, which is usually 80.

logii’s picture

I'm not sure of which is the actual WWW root, because I'm using a subdomain sitting outside of "public_html" of the main doamin.
the File structure Cpanel usually recommend is:
[public_html]
- [subdomain1]
- [subdomain2:nodejs]
- [subdomain3]

But my current subdomains where created along side with public_html instead:
[public_html]
[subdomain1]
[subdomain2:nodejs]
[subdomain3]

With my current situation, I'm assuming that my webroot should be: '/nodejs/auth/'?
I'm continually trying to get this to work right now and will post updates once I got this working.
Meanwhile, any help is appreciated.

logii’s picture

afeijo, You were right. Thanks!
By adding that folder, now it works.

However it was relative to my home directory '~/'
Just like what I posted above.

Anonymous’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

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

jeff h’s picture

Just a note for anyone else experiencing similar issues; in my case at least I had to restart the node.js server before any changes to the authPath (in nodejs.config.js) took effect.

rootrau’s picture

help me fix error

Backend authentication url not found, full response info: { socket:
{ bufferSize: 0,
fd: null,
type: 'tcp4',
allowHalfOpen: false,
_writeImpl: [Function],
_readImpl: [Function],
_shutdownImpl: [Function],
_readWatcher: null,
destroyed: true,
readable: false,
_writeQueue: [],
_writeQueueEncoding: [],
_writeQueueFD: [],
_writeQueueCallbacks: [],
_writeWatcher: null,
writable: false,
_connecting: false,
_events:
{ connect: [Function],
error: [Function],
close: [Function] },
_httpConnecting: false,
_httpMessage: null,
ondrain: [Function],
ondata: [Function],
onend: [Function],
_idleNext: null,
_idlePrev: null },
connection:
{ bufferSize: 0,
fd: null,
type: 'tcp4',
allowHalfOpen: false,
_writeImpl: [Function],
_readImpl: [Function],
_shutdownImpl: [Function],
_readWatcher: null,
destroyed: true,
readable: false,
_writeQueue: [],
_writeQueueEncoding: [],
_writeQueueFD: [],
_writeQueueCallbacks: [],
_writeWatcher: null,
writable: false,
_connecting: false,
_events:
{ connect: [Function],
error: [Function],
close: [Function] },
_httpConnecting: false,
_httpMessage: null,
ondrain: [Function],
ondata: [Function],
onend: [Function],
_idleNext: null,
_idlePrev: null },
httpVersion: '1.1',
complete: true,
headers:
{ date: 'Mon, 26 Sep 2011 08:49:14 GMT',
server: 'Apache/2.2.15 (CentOS)',
'content-length': '401',
connection: 'close',
'content-type': 'text/html; charset=iso-8859-1' },
trailers: {},
readable: false,
url: '',
method: null,
statusCode: 404,
client:
{ bufferSize: 0,
fd: null,
type: 'tcp4',
allowHalfOpen: false,
_writeImpl: [Function],
_readImpl: [Function],
_shutdownImpl: [Function],
_readWatcher: null,
destroyed: true,
readable: false,
_writeQueue: [],
_writeQueueEncoding: [],
_writeQueueFD: [],
_writeQueueCallbacks: [],
_writeWatcher: null,
writable: false,
_connecting: false,
_events:
{ connect: [Function],
error: [Function],
close: [Function] },
_httpConnecting: false,
_httpMessage: null,
ondrain: [Function],
ondata: [Function],
onend: [Function],
_idleNext: null,
_idlePrev: null },
httpVersionMajor: 1,
httpVersionMinor: 1,
upgrade: false,
_events: { end: [ [Function], [Function] ], data: [Function] },
_decoder:
{ encoding: 'utf8',
charBuffer: ,
charReceived: 0,
charLength: 0 } }
nodejs beta6

neovinhtru’s picture

Hi everybody!
can you help me? i was using nodejs and drupal chat, i did run node server.js but drupalchat not working.
i was getting messages this.
--------------
[root@mail nodejs]# node server.js
Started http server.
info - socket.io started
Failed to parse authentication message: [SyntaxError: Unexpected token <]
Failed to parse authentication message: [SyntaxError: Unexpected token <]
Failed to parse authentication message: [SyntaxError: Unexpected token <]
Failed to parse authentication message: [SyntaxError: Unexpected token <]
Failed to parse authentication message: [SyntaxError: Unexpected token <]
----------------
Thanks!

deoashish’s picture

I getting similar issue.Please tell me way to resolve it

sunset_bill’s picture

I was getting this, too, on a new install. What fixed it for me was enabling Clean URLs.