brunch / auto-reload-brunch

Adds automatic browser reloading support to brunch.
88 stars 30 forks source link

Error: Failed to construct 'WebSocket': The URL 'ws://:9486' is invalid. #53

Closed kevinrenskers closed 9 years ago

kevinrenskers commented 9 years ago

Hi guys. I'm trying to use brunch with auto-reload-brunch for a node-webkit (now NW.js) project.

My package.json:

{
  "name": "slingchat-nw-build",
  "version": "0.0.1",
  "main": "_public/index.html",
  "scripts": {
    "watch": "brunch watch",
    "open": "nw _public"
  },
  "dependencies": {
    "auto-reload-brunch": "1.7.x",
    "brunch": "1.7.x",
    "css-brunch": "1.7.x",
    "javascript-brunch": "1.7.x",
    "less-brunch": "1.7.x",
    "nw": "^0.12.0-alpha2"
  }
}

My config.coffee:

exports.config =
  modules:
    definition: false
    wrapper: false

  paths:
    public: '_public'

  files:
    javascripts:
      joinTo:
        'js/app.js': /^app/

    stylesheets:
      joinTo:
        'css/app.css': /^app/

  minify: true

When I run npm run watch (which runs brunch watch) I see that the autoreload script is prepended to _public/js/app.js. However when I then run npm run open I get the following error in the console and autoreload doesn't work:

[16989:0125/125155:ERROR:nw_shell.cc(324)] Error: Failed to construct 'WebSocket': The URL 'ws://:9486' is invalid.
    at Error (native)
    at connect (file:///Users/kevin/Workspace/slingchat-nw/_public/js/app.js:40:22)
    at file:///Users/kevin/Workspace/slingchat-nw/_public/js/app.js:54:3
    at file:///Users/kevin/Workspace/slingchat-nw/_public/js/app.js:55:3
[16989:0125/125155:INFO:CONSOLE(40)] "Uncaught SyntaxError: Failed to construct 'WebSocket': The URL 'ws://:9486' is invalid.", source: file:///Users/kevin/Workspace/slingchat-nw/_public/js/app.js (40)

Node-webkit opens the local file file:///Users/kevin/Workspace/slingchat-nw/_public/index.html, is that maybe the problem? How would I make this work? The whole idea behind node-webkit is of course to open a local file rather then something running off a server.

es128 commented 9 years ago

https://github.com/brunch/auto-reload-brunch/blob/master/vendor/auto-reload.js#L37

You need to set the window.brunch.server setting on the client side since window.location.hostname doesn't resolve to anything with the local file. Setting it to 'localhost' or the like ought to work.

kevinrenskers commented 9 years ago

Thank you for your very quick and helpful answer. It's working as expected now.