šŸš€ Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more →
Socket
Sign inDemoInstall
Socket

@bit-js/bun-ws

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
Package was removed
Sorry, it seems this package was removed from the registry

@bit-js/bun-ws

A simple WebSocket router for Bun.

1.0.1
unpublished
latest
npm
Version published
Maintainers
1
Created
Source

bun-ws

A simple WebSocket router for Bun.

Usage

Route file:

import { route } from '@bit-js/bun-ws';

export default route<{ id: string }>({
    message(ws) {
        ws.send(ws.data.id);
    }
});

Use with a fetch handler.

import route from './route';

export default function fetch(req: Request) {
    route.upgrade(req, {
        data: { id: performance.now().toString() }
    });
}

Entry point:

import fetch from './fetch';
import { serve } from '@bit-js/bun-ws';

// Create a server and bind all registered routes to that server
const server = serve({
    // Bun server options
    server: { fetch },

    // WebSocket base handler options (without handlers)
    ws: { publishToSelf: true }
});

Use bind if you already have a server instance not created using serve:

import { bind } from '@bit-js/bun-ws';

// Bind all registered routes to a server
bind(server);

FAQs

Package last updated on 15 Mar 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts