Reputation: 21
Has anybody had luck creating a website with real-time communication (chat) using Nodejs and websockets on Fastcomet? I've submitted many tickets to Fastcomet but we keep going in circles.
My goal is to put something like https://davidwalsh.name/websocket online at www.mywebsite.com/socketio
All my tests work locally when I open http://127.0.0.1:3000/ in my browser.
I started by setting up a Node.js app from cpanel
then fill in the details
This procedure creates a .htaccess file for Phusion Passenger.
even tried RewriteRule ^(.) http://localhost:3000/$1 [P]*
When I go to www.mywebsite.com/socketio I get the following error:
http://www.mywebsite:3000/socket.io/?EIO=3&transport=polling&t=1531226905601-0 Failed to load resource: net::ERR_NAME_NOT_RESOLVED
Here is another failed test:
Server index.js (Nodejs status: started)
var http = require('http');
var server = http.createServer(function(req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
var message = 'It works!\n',
version = 'NodeJS ' + process.versions.node + '\n',
response = [message, version].join('\n');
res.end(response);
});
server.listen();
const WebSocket = require('ws');
const wss = new WebSocket.Server({ port: 8080 });
wss.on('connection', function connection(ws) {
ws.on('message', function incoming(message) {
console.log('received: %s', message);
});
ws.send('something')
});
client index.html
<html>
<head>
<script>
var sock =new WebSocket('ws://' + window.location.host+"/chat" );
</script>
</head>
<body>
</body>
</html>
even tried
var sock =new WebSocket('ws://' + window.location.host+":8080/chat" );
I also changed port 8080 to 3000 for the index.js and index.html
I even removed port from index.js and index.html
Access through browser at:
http://www.mywebsite.com/chat/index.html
Error:
WebSocket connection to 'ws://www.mywebsite.com/chat' failed: Error during WebSocket handshake: Unexpected response code: 500
Anybody have ideas?
Upvotes: 2
Views: 1796
Reputation: 21
Have you tried creating your project outside the public_html folder?
Try creating a folder (eg: home/user/socket_test) and put your code inside that folder and point your node.js app to that path.
Ports are mapped automatically in "Phusion Passenger" meaning whatever port you specify in the program will be automatically reverse mapped by phusion passenger.
Use port 3000 for node apps, example.com/app will have port of 8080 getting mapped to port 3000.
I'm using Fastcommet shared hosting plan and running a node express RESTful API and its working very well.
Upvotes: 0