Socket.io chat, setting url

Asked

Viewed 450 times

2

I would like a help with chat using socket.io, I would like to define a URL, I am not getting, I can only access through localhost:3000.

For example I wanted the chat to be on the homepage of my website example: siteexemplo.com.br, how do I define it? how do I start server.js inside the server?

My code:

SERVER.JS

var socket  = require( './node_modules/socket.io' );
var express = require('./node_modules/express');
var app     = express();
var server  = require('http').createServer(app);
var io      = socket.listen( server );
var port    = process.env.PORT || 3000;

chat js.

var socket = io.connect( 'http://'+window.location.hostname+':3000' );

Another question, as I define my index, for PHP?

I made the change in the code below:

app.use(express.static(__dirname + '/'));
app.get('/', function(req, res){
    res.sendFile(__dirname + '/index.php'); 

});

But when you access the site, it automatically downloads the page...

  • Your server is apache?

  • Yeah, he’s an Apache...

  • I’ll see if I can help

  • If you understand English it helps: http://stackoverflow.com/questions/16573668/best-practices-when-running-node-js-with-port-80-ubuntu-linode

  • @Miguel And is it possible to run a Nodejs with apache server? Or run the socket.io on an apache server? At least in the hosting server I use I could not precisely this because of this limitation (as I was informed by the technical support).

  • Cannot run Nodejs on shared servers as Nodejs requires shell access to which unsigned hosts do not provide.

  • What would be the option of making a chat then?

Show 2 more comments

3 answers

0

To answer your second question, if you are using an Apache server go to httpd.conf which is usually located in a +- folder so depending on your version: Installation path \bin\apache\apache2.4.18\conf.

You open the file, I usually open it with the notepad and find a part of the file that says DirectoryIndex (not commented) and changes what is in front of the property to index.php or any other name with the extension php.

-1

In this case, the two cannot be at port 3000, because there will be a port conflict, what I recommend in this case, is to use the port 3001, while the port 3000 is at the front, so you will have to use two npm start.

-3

Browser other questions tagged

You are not signed in. Login or sign up in order to post.