File tree Expand file tree Collapse file tree 5 files changed +28
-3
lines changed
Expand file tree Collapse file tree 5 files changed +28
-3
lines changed Original file line number Diff line number Diff line change 11
22node_modules /
3+ * .pem
Original file line number Diff line number Diff line change 22# Socket.IO Fiddle
33
44```
5+ $ sh generate.sh # create self-signed keys for server-ssl.js
56$ npm install
67$ npm start # run the server
78$ npm run client # run the nodejs client
89```
910
10- And point your browser to ` http ://localhost:3000` . Optionally, specify
11+ And point your browser to ` https ://localhost:3000` . Optionally, specify
1112a port by supplying the ` PORT ` env variable.
13+
14+ You will have to accept the self-signed warning. Older versions of node are known to have issues. This is a way to test your version of node.
15+
16+ ** Known versions to work with SSL/TLS: v8.1.3 -- expect newest versions of v6 and v4 to also work (untested)!**
Original file line number Diff line number Diff line change 11
2- const socket = require ( 'socket.io-client' ) ( 'http://localhost:3000' ) ;
2+ // for the following to work, you'll have to answer "localhost" at the Common Name question when running generate.sh
3+ // > Common Name (e.g. server FQDN or YOUR name) []:localhost
4+ const fs = require ( 'fs' ) ;
5+ const socket = require ( 'socket.io-client' ) ( 'https://localhost:3000' , {
6+ rejectUnauthorized : true , // default value
7+ ca : fs . readFileSync ( './cert.pem' )
8+ } ) ;
9+
10+ // USE WITH CAUTION! The following disables the validation of the server's identity
11+ // see https://nodejs.org/docs/latest/api/tls.html#tls_tls_createserver_options_secureconnectionlistener
12+ // const socket = require('socket.io-client')('https://localhost:3000', {
13+ // rejectUnauthorized: false
14+ // });
315
416socket . on ( 'connect' , onConnect ) ;
517
Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+ echo " You can optionally answer the question, or 'enter' for defaults:"
3+ openssl req -newkey rsa:2048 -nodes -keyout key.pem -x509 -days 3650 -out cert.pem
Original file line number Diff line number Diff line change 11
22const express = require ( 'express' ) ;
33const app = express ( ) ;
4- const server = require ( 'http' ) . createServer ( app ) ;
4+ const fs = require ( 'fs' ) ;
5+ const server = require ( 'https' ) . createServer ( {
6+ key : fs . readFileSync ( './key.pem' ) ,
7+ cert : fs . readFileSync ( './cert.pem' ) ,
8+ } , app ) ;
59const io = require ( 'socket.io' ) ( server ) ;
610const port = process . env . PORT || 3000 ;
711
You can’t perform that action at this time.
0 commit comments