The proxied-worker tech for NodeJS

Overview

proxied-node

This is exactly the same proxied-worker module, specific for a NodeJS proxied namespace.

The only difference is that the client side is already the exported namespace, not a Worker to initialize.

Check the oled screen demo to try it out on a Raspberry Pi.

API

The default export is a common server handler factory function.

It accepts few configurations options to enable a variety of use cases, even multiple proxied namespaces, whenever that's needed.

// same as: const proxiedNode = require('proxied-node');
import proxiedNode from 'proxied-node';

// handler(request, response, next = void 0)
const handler = proxiedNode({
  wss,        // a WebSocketServer options or a WebSocketServer instance
  namespace,  // the namespace to proxy to each client
  match,      // an optional client side URL to match. By default is /js/proxied-node.js
  host,       // an optional host name to use. it's IPv4 / localhost otherwise
  port,       // an optional  port to use when wss is an instance of WebSocketServer already
});

// express
app.use(handler);

// or standard http
createServer((req, res) => {
  if (handler(req, res))
    return;
  // ... rest of the logic
});

Server Side Example

const express = require('express');
const proxiedNode = require('proxied-node');

const {PORT = 8080} = process.env;

const app = express();

const handler = proxiedNode({
  wss: {port: 5000},
  namespace: {
    test: 'OK',
    exit() {
      console.log('bye bye');
      process.exit(0);
    },
    sum(a, b) {
      return a + b;
    },
    on(type, callback) {
      setTimeout(() => {
        callback('Event', type);
      });
    },
    async delayed() {
      console.log('context', this.test);
      // postMessage({action: 'greetings'});
      return await new Promise($ => setTimeout($, 500, Math.random()));
    },
    Class: class {
      constructor(name) {
        this.name = name;
      }
      sum(a, b) {
        console.log(this.name, a, b);
        return a + b;
      }
    }
  }
});

app.use(handler);
app.use(express.static(__dirname));
app.listen(PORT);

Client Side Example

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>proxied-node</title>
  <script type="module">
  // the namespace is exported automatically as default
  import('/proxied-node.js').then(async ({default: nmsp}) => {
    console.log(await nmsp.test);
    console.log(await nmsp.sum(1, 2));
    await nmsp.delayed();

    const instance = await new nmsp.Class('🍻');
    console.log(await instance.sum(1, 2));

    nmsp.on('listener', type => {
      console.log('listener', type);
    });

    const btn = document.body.appendChild(document.createElement('button'));
    btn.addEventListener('click', () => { nmsp.exit(); });
    btn.textContent = '☠ exit';
  });
  </script>
</head>
</html>
You might also like...

A VS Code extension for solving problems from WorkAt.tech

A VS Code extension for solving problems from WorkAt.tech

VSCode-WorkAt VSCode-WorkAt is an extension that lets you write code for WorkAt.tech in VSCode. Check it out on the Marketplace. Features Choose a lan

Aug 29, 2022

Low tech template for a reduced carbon impact :seedling:

Enverse minimalist front-end template 🌱 🌱 For all else, use Astro.build 😃 Recomended package manager: pnpm Preact + Typescript + Vite How to use: F

Jan 10, 2022

Visualize your tech stack and database with a simple, beautiful, and interactive web app.

Stacify Visualize your tech stack and database with a simple, beautiful, and interactive web app. Why Stacify Why would you want to use Stacify? Well,

Jan 20, 2022

This is a project to testing coding habilities, it is part of the recruiting process of Liven.tech company

This is a project to testing coding habilities, it is part of the recruiting process of Liven.tech company

Feb 26, 2022

Different Types of Monsters Card of Popular anime. Build in React tech.

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: ya

Mar 19, 2022

Blog-webapp - A simple webapp prototype that serves tech news, blogs, and anything else a developer might want to learn or get help with

Blog-webapp - A simple webapp prototype that serves tech news, blogs, and anything else a developer might want to learn or get help with

Blog Web app A simple webapp prototype that serves tech news, blogs, and anythin

Nov 3, 2022

Desafio Gerador de senhas com Emojis - Tech da Semana 😁 🤩

 Desafio Gerador de senhas com Emojis - Tech da Semana 😁 🤩

Desafio Gerador de senhas com Emojis - Tech da Semana 😁 🤩 📚 Informações sobre o projeto O projeto foi desenvolvido com base no desafio do Discord d

Nov 21, 2022

An online stem player. Inspired by but not affiliated with YEEZY TECH X KANO Stem Player.

Stem Player Online An online stem player. Inspired by but not affiliated with YEEZY TECH X KANO Stem Player. https://stemplayeronline.com See the proj

Nov 13, 2022

Primeiro projeto do Módulo 1 da Blue ed Tech - Web Fullstack

Primeiro projeto do Módulo 1 da Blue ed Tech - Web Fullstack

Projeto1-Modulo1-BlueFullstack Módulo 1 - Blue ed Tech - Web Fullstack Projeto 1 - A Jornada do Herói A premissa é a seguinte: O nosso herói chegou ao

Mar 9, 2022

😂 is a self-hostable blog engine built on the tech that powers christine.website

😂 😂 is a blog engine powered by Deno. 😂 has no canonical pronunciation, and users are not encouraged to come up with one. 😂 is and always will be

Sep 4, 2022

A tool that leverages the knowledge of experienced engineers to provide tech stack suggestions for your next application.

StackGen Key technologies used React React Router and Context API PostgreSQL React Testing Library Authentication Mantine The Problem There is an over

Jun 9, 2022

The first place winning no-code platform for generating developer resume pages, designed for and submitted to the 2022 Tech Optimum Hackathon.

Genfolio Genfolio is a no-code platform for generating developer portfolios. A demo can be found on the project's devpost or on youtube. Our stack We

Dec 5, 2022

Simple budget-tracker web app developed using Vanilla JavaScript. Exercise from Warren Tech Academy.

Simple budget-tracker web app developed using Vanilla JavaScript. Exercise from Warren Tech Academy.

Willow Personal Finance - Exercise from Warren Tech Academy About Project screenshots Installation Extra notes About Tools: HTML CSS (SASS) JavaScript

Dec 14, 2022

Catamyst Frontend Stack - Discussion and demo for Frontend Web Development with Modern Tech Stack

Catamyst Frontend Stack Discussion and demo for Frontend Web Development with Modern Tech Stack. Made by M Haidar Hanif from Catamyst. Haidar is the F

Dec 24, 2022

Integration with https://neon.tech Serverless Postgres

README Welcome to RedwoodJS! Prerequisites Redwood requires Node.js (=14.19.x =16.x) and Yarn (=1.15) Are you on Windows? For best results, follow

Sep 16, 2022

Triumph Tech’s Magnus Editor is a full-featured remote editor for Rock RMS.

Triumph Tech’s Magnus Editor is a full-featured remote editor for Rock RMS.

Magnus Visual Studio Code Editor for Rock RMS Triumph Tech’s Magnus Editor is a full-featured remote editor for Rock RMS. Rock RMS is an open source R

Nov 23, 2022

A "link in bio" site built using the "T3" tech stack.

Create T3 App This is an app bootstrapped according to the init.tips stack, also known as the T3-Stack. Why are there .js files in here? As per T3-Axi

Sep 5, 2022

InReach is the world’s first tech platform matching LGBTQ+ people with safe, verified resources.

Explore the screenshots » Report a Bug · Request a Feature . Ask a Question Table of Contents About Built With Getting Started Prerequisites Installat

Jan 3, 2023

A website to list tech twitter creators, across the world.

A website to list tech twitter creators, across the world.

TechCreators A website to list tech twitter creators, across the world. Languages/Tools 👩🏽‍💻 Demo Check out the website: TechCreators 👇🏽 Prerequi

Jan 3, 2023
Comments
  • Proxied-node without websocket

    Proxied-node without websocket

    Is it possible to use proxied-node without websocket and Is it possible to pass request object to namespaces. I want to use JWT authentication/authorization for limiting access to namespaces.

    opened by ansarizafar 7
Owner
Andrea Giammarchi
Web, Mobile, IoT and all Web & JS things since 00's
Andrea Giammarchi
实现一个基于 nodejs 的 cli 工具

teach-koa-setup 实现一个基于 nodejs 的 cli 工具,动态创建基于 koa 的代码模板 使用 本地使用 npm link 调用 teach-koa-setup 即可 技术 nodejs chalk ejs execa inquirer aaa 学习 可以去 b站 观看完整

阿崔cxr 29 May 17, 2022
ZippyDamn-lib! is a ZippyShare Unofficial library (downloader & search) for nodejs

ZippyDamn-lib! ZippyDamn-lib! is a ZippyShare Unofficial library (downloader & search) for nodejs Looking for a CLI? Try Zippydamn! CLI Installation U

Virdio Samuel 4 Oct 2, 2021
NodeJS app to dynamically update your twitter header with AP Dhillon's lyrics

header-dhillon A NodeJS app that dynamically updates your twitter header with 2 lines of random lyrics from any random track by the punjabi artist AP

Raj Shankar Tiwary 4 Jul 25, 2022
⚡️The Fullstack React Framework — built on Next.js

The Fullstack React Framework "Zero-API" Data Layer — Built on Next.js — Inspired by Ruby on Rails Read the Documentation “Zero-API” data layer lets y

⚡️Blitz 12.5k Jan 4, 2023
A Nest JS App that is proxied to deta.sh

Description Nest framework TypeScript starter repository. Installation $ yarn Running the app # development $ yarn start # watch mode $ yarn run star

Julian 7 Nov 18, 2022
Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

Svante Jonsson IT-Högskolan 3 May 18, 2022
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
100% web real-time audio experiment using smartphones as effect controller. (tech: Android Chrome + WebRTC + Web Audio API)

beez 100% web real-time audio experiment using smartphones as effect controller. (tech: Android Chrome + WebRTC + Web Audio API) The concept An Hive i

Gaëtan Renaudeau 34 Dec 16, 2022
Frontend tech guide and collection of highly recommended materials

Frontend Learning Kit Frontend tech guide and collection of highly recommended materials Show your support by giving a ⭐ to this repo 2022 Frontend De

Sadanand Akshay Pai 2.9k Jan 7, 2023