proxy-socks

0.0.3 • Public • Published

Proxy Socks 🧦 🧦

Library for creating a reverse proxy over websockets.

Request/Response <-HTTP-> [Server] <-WS-> [Agent]

Quick Start

  1. Create Server (Deno)
import { Server } from "npm:websocket-reverse-proxy";
const server = new Server(() => new Response("no responder", { status: 500 })); //
Deno.serve({ port: 8082 }, (req) => {
  if (req.headers.get("upgrade") !== "websocket") {
    return server.fetch(req);
  }
  const { socket: connection, response } = Deno.upgradeWebSocket(req);
  server.addConnection(connection);
  connection.addEventListener("close", () => {
    server.removeConnection(connection);
  });
  return response;
});
  1. Create Agent
import { Agent } from "websocket-reverse-proxy";
const address = `ws://localhost:8082`;
const { serve } = new Agent(address, { reconnect: 1000, log: 2 });
serve(async (request, { id }) => {
  return new Response(`Hello there!`, {
    status: 200,
    statusText: "OK",
    headers: {
      "content-type": "application/text",
      etag: id,
    },
  });
});

Package Sidebar

Install

npm i proxy-socks

Weekly Downloads

1

Version

0.0.3

License

ISC

Unpacked Size

23.5 kB

Total Files

14

Last publish

Collaborators

  • johnhenry