Skip to content

Instantly share code, notes, and snippets.

@chainhead
Last active March 24, 2021 05:00

Revisions

  1. @nsubrahm-aws nsubrahm-aws revised this gist Mar 24, 2021. 1 changed file with 13 additions and 0 deletions.
    13 changes: 13 additions & 0 deletions upgrade.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    const http = require('http');
    const WebSocket = require('ws');

    const server = http.createServer();
    const wss = new WebSocket.Server({ noServer: true });

    server.on('upgrade', (request, socket, head) => {
    wss.handleUpgrade(request, socket, head, function done(w) {
    wss.emit('connection', ws, request)
    })
    })

    server.listen(8080)
  2. chainhead created this gist Mar 24, 2021.
    3 changes: 3 additions & 0 deletions 0-intro.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    # Introduction

    This gist shows a basic implementation of a HTTP server that handles the request to upgrade connection to Websockets.