This is a simple chat app written to demonstrate using vanilla WebSockets in a Node.js app hosted by Phusion Passenger (specifically on DreamHost).
The code is heavily modified from an example app showing how to write a chat app using socket.io. The original code is available on GitHub.
I wrote this to test using WebSockets hosted by DreamHost Shared Hosting.
Disclaimer: I am in no way affiliated with DreamHost, and this app is not sanctioned by DreamHost in any way. It is your responsibility to make sure that your use of this code complies with the DreamHost Terms of Service.
This app should work when run either locally or when hosted by Phusion Passenger.
git clone [email protected]:benjaminkraus/testPassengerWebSockets.git
cd testPassengerWebSockets
npm install
mkdir cert
cd cert
openssl req -x509 -newkey rsa:2048 -keyout keytmp.pem -out cert.pem -days 365
openssl rsa -in keytmp.pem -out key.pem
cd ..
node app.js
Load the app from https://localhost:8080/.
Disclaimer: I am in no way affiliated with DreamHost, and this app is not sanctioned by DreamHost in any way. It is your responsibility to make sure that your use of this code complies with the DreamHost Terms of Service.
For instructions on configuring Node.js on DreamHost, you can visit these guides:
Once Node.js is working, download and install the code.
git clone [email protected]:benjaminkraus/testPassengerWebSockets.git
cd testPassengerWebSockets
npm install
Move the code into the directory created by DreamHost for your app.
- Visit the DreamHost Panel SSL/TLS Certificates page.
- Select the domain you are using for WebSockets.
- Copy the text from
Certificate
into a file namedcert.pem
. - Copy the text from
RSA Private Key
into a file namedkey.pem
. - Place
cert.pem
andkey.pem
into a directory namedcert
.
touch tmp/restart.txt
There are two configuration options that can be changed using a .env
file. For example:
PORT=8080
WSPORT=8081
PORT
controls the port used for the HTTPS server. Default value8080
, unless hosted by Phusion Passenger.WSPORT
controls the port number used for the WebSockets server. Default value when hosted locally is the same as thePORT
number. The default value when hosted by Phusion Passenger is8080
.- If hosted on Phusion Passenger,
PORT
is ignored and controlled by Phusion Passenger, and the WebSockets server is always hosted on a different port.