Skip to content

Instantly share code, notes, and snippets.

@memandip
Created July 31, 2019 06:08
Show Gist options
  • Save memandip/12cd1b95b37b8379ace3c1a977bb126a to your computer and use it in GitHub Desktop.
Save memandip/12cd1b95b37b8379ace3c1a977bb126a to your computer and use it in GitHub Desktop.
Socket.io https websocket server with custom web socket url
const fs = require('fs')
const https = require('https')
const app = require('express')()
var privateKey = fs.readFileSync('./privatekey.pem', 'utf8')
var certificate = fs.readFileSync('./certificate.pem', 'utf8')
const credentials = {key: privateKey, cert: certificate}
const httpsServer = https.createServer(credentials, app)
// const server = require('http').createServer(app)
const io = require('socket.io')(httpsServer, {path:'/web/socket'})
io.on('connection', client => {
console.log('client conneted')
client.on('disconnect', () => console.log('client disconnected'))
})
httpsServer.listen(8081, () => 'https server listening on port 8081')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment