Giter Club home page Giter Club logo

express-bridge's Introduction

Express-Bridge for node.js

Make API calls between a public webserver and a local network without DynDNS.

Browser <-> Webserver (Cloud) <- Express-Bridge -> Local Network (btw. Raspberry) -> Smart Home Device

Express-Bridge sends data to a server on a local network without having to open the network to the outside. The bridge can be used to forward API calls from the web server to smart home devices in your private local network.

For example: Amazon Alexa makes an API call to your webserver with a "turn light on" command. Your webserver sends this request over the express-bridge to a local server (btw. respberry) in your home. After the server turns the light on, then send a response over the bridge back to Alexa.

Examples

Server (public webserver)

const bridge = require('express-bridge');
const server = new bridge.Server(server: {http: {port: 80}});

server.start((err) => {});

Client (local raspberry)

const bridge = require('express-bridge');
const client = new bridge.Client('http://<webserver-domain>:80');

client.route('/light/:lightId/turn/:action', (req, res, next) => {
    console.log('Incoming data:', req);
    res.send({ status: 'ok' });
});

client.start((err) => {});

How does it work

  1. Starting the webserver
$ DEBUG=express-bridge/* node examples/server-bridge.js
  1. Starting the local server
$ DEBUG=express-bridge/* node examples/local-client.js
  1. Make a browser request to the webserver
http://<webserver-domain>/light/livingroom/turn/on

Incoming message format

{
    id: 'a86ba5b6-3f25-4fb8-a5ac-3f60d06b26fe',
    method: 'GET',
    path: '/light/livingroom/turn/on',
    headers: {
        'cache-control': 'no-cache',
        'user-agent': 'PostmanRuntime/6.4.1',
        'accept': '*/*',
        'accept-encoding': 'gzip, deflate',
        'content-length': '170',
        'connection': 'keep-alive'
    },
    params: {
        lightId: 'livingroom',
        action: 'on'
    },
    query: {},
    body: {}
}

express-bridge's People

Watchers

Frank Teller avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.