linemanjs / lineman

Lineman helps you build fat-client JavaScript apps. It produces happiness by building assets, mocking servers, running specs on every file change
MIT License
1.18k stars 83 forks source link

Error: io is not defined when using socket.io with linemanJS #327

Closed swapneshk closed 9 years ago

swapneshk commented 9 years ago

Following is my app.js file (backend- api end) - http://pastebin.com/4KRASm4a

In my frontend app template I am using following code to test if its working or not, but it is throwing error Error: io is not defined

<script src="/socket.io/socket.io.js"></script>
<script>
  var socket = io.connect('http://localhost:6868');
  socket.on('news', function (data) {
    console.log(data);
    socket.emit('my other event', { my: 'data' });
  });
</script>

My application file looks like - http://pastebin.com/hDbrtQ1h

Let me know what I am doing wrong here if any.

davemo commented 9 years ago

Lineman runs its own express for serving static assets and proxying api requests to a backend that you define in config/application.js under the server key. IIRC, the /socket.io/socket.io.js url you have in your frontend template is wired up by var io = require('socket.io')(server);

Given that the above line is in your express server and not Linemans dev server there is no way for Lineman to serve up that file.

To fix this you could modify config/server.js to do what you want with socket.io, or just include the client-side library statically in vendor/js.

Cheers :)