I made a web chat application using Node.js, socket.io and express. It's working well.
Now I want to move my chat application into my website but i have problem with paths.
My website is based on Laravel framework and has this structure.
Website
/public
/js
/jquery1-10.js
/chat.js ----> client side chat file.
/app.js ----> node.js server side file.
/index.php
Laravel use layouts so in index.php
file, URL::asset('/path-to-file')
is working well for all files inside public directory. including stylesheets and javascript.
Inside my index.php
file I call javascripts this way:
<script src="{{ asset('js/jquery1-10.js'); }}" ></script> // public/js/jquery1-10.js
<script src="{{ asset('js/chat.js'); }}" ></script> // public/js/chat.js
<script src="{{ asset('/socket.io/socket.io.js'); }}" ></script> // ???
both jquery1-10.js
and chat.js
loads well
BUT can't load socket.io file. I think socket.io creates automatically! and I have no idea where it is.
Can somebody help me with this?
this is app.js
file:
var http = require("http");
var express = require("express"),
app = express(),
server = http.createServer(app),
io = require("socket.io").listen(server);
server.listen(4000);
app.get("/*", function( req, res ) {
res.sendfile( __dirname + "/index.php" );
});
And this is my chat.js file --> client side.
jQuery( function($){
var socket = io.connect(); ---> error happens here. can not load socket.io.js file
Solved
well, I used this line:<script src="http://localhost:4000/socket.io/socket.io.js" ></script>
instead of this:<script src="{{ asset('/socket.io/socket.io.js'); }}" ></script>
and it worked well.