Skip to content

benjaminkraus/testPassengerWebSockets

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple Chat using Node.js, Express, and WebSockets on Phusion Passenger

Motivation

This is a simple chat app written to demonstrate using vanilla WebSockets in a Node.js app hosted by Phusion Passenger (specifically on DreamHost).

Background

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.

Setup

This app should work when run either locally or when hosted by Phusion Passenger.

Running Locally

Download and install NPM modules

git clone [email protected]:benjaminkraus/testPassengerWebSockets.git
cd testPassengerWebSockets
npm install

Create SSL certificates. Run the last three commands separately.

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 ..

Start the server

node app.js

Load the app

Load the app from https://localhost:8080/.

Hosting on DreamHost

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.

Set-up Node.js on DreamHost

For instructions on configuring Node.js on DreamHost, you can visit these guides:

Download and install NPM modules

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.

Copy SSL certificates

  1. Visit the DreamHost Panel SSL/TLS Certificates page.
  2. Select the domain you are using for WebSockets.
  3. Copy the text from Certificate into a file named cert.pem.
  4. Copy the text from RSA Private Key into a file named key.pem.
  5. Place cert.pem and key.pem into a directory named cert.

Restart the server

touch tmp/restart.txt

Optional Configuration

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 value 8080, unless hosted by Phusion Passenger.
  • WSPORT controls the port number used for the WebSockets server. Default value when hosted locally is the same as the PORT number. The default value when hosted by Phusion Passenger is 8080.
  • If hosted on Phusion Passenger, PORT is ignored and controlled by Phusion Passenger, and the WebSockets server is always hosted on a different port.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published