Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@domoinc/ryuu-proxy

Package Overview
Dependencies
Maintainers
17
Versions
59
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@domoinc/ryuu-proxy

a middleware that provides a proxy for local domo app development

  • 1.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
382
increased by809.52%
Maintainers
17
Weekly downloads
 
Created
Source

ryuu-proxy

Simple middleware to add to a local development server while developing Domo Apps. The middleware will intercept any calls to /data/v1 or /domo/v1, proxy an authenticated request to the Domo App service, and pipe the response back so that you can develop your Domo App locally and still get request data from Domo.

Installation

npm install @domoinc/ryuu-proxy --save-dev

Usage

This library leverages the last login session from your Domo CLI. If that session is no longer active or doesn't exist then the proxy won't work. Be sure that you've logged in before you start working:

$ domo login

Express / Connect

This library comes with a simple wrapper for Express/Connect middleware.

const express = require('express');
const { Proxy } = require('@domoinc/ryuu-proxy');

const app = express();

const manifest = require('./path/to/app/manifest.json');
const proxy = new Proxy(manifest);

app.use(proxy.express());

Build Your Own

For other frameworks, the library exposes the necessary functions to create a stream to pipe back to your server. You'll need to handle this stream as your server would expect. The only thing that stream() expects is a standard Node Request which most server frameworks extend in some way.

// koa
app.use(async (ctx, next) => {
  await proxy
    .stream(ctx.req)
    .then(data => ctx.body = ctx.req.pipe(data))
    .catch(next);
});
// express
app.use((req, res, next) => {
  proxy
    .stream(req)
    .then(stream => stream.pipe(res))
    .catch(() => next());
});
// node http
const server = http.createServer((req, res) => {
  if (req.url === '/') {
    loadHomePage(res);
  } else {
    proxy
      .stream(req)
      .then(stream => stream.pipe(res));
  }
});
Error Handling

Ignoring the errors will cause the proxy to fail silently and the proxy request will return a 404 error. If you'd like a little more detail on the errors you can expose them in the response:

// koa
app.use(async (ctx, next) => {
  await proxy
    .stream(ctx.req)
    .then(data => ctx.body = ctx.req.pipe(data))
    .catch((err) => {
      if (err.name === 'DomoException') {
        ctx.status = err.status || err.statusCode || 500;
        ctx.body = err;
      } else {
        next();
      }
    });
});
// express / connect
app.use((req, res, next) => {
  proxy
    .stream(req)
    .then(stream => stream.pipe(res))
    .catch(err => {
      if (err.name === 'DomoException') {
        res.status(err.status || err.statusCode || 500).json(err);
      } else {
        next();
      }
    });
});
// http
const server = http.createServer((req, res) => {
  if (req.url === '/') {
    loadHomePage();
  } else {
    proxy
      .stream(req)
      .then(stream => stream.pipe(res))
      .catch(err => {
        if (err.name === 'DomoException') {
          res.writeHead(err.status || err.statusCode || 500);
          res.end(JSON.stringify(err));
        }
      });
  }
});

Keywords

FAQs

Package last updated on 01 Dec 2017

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc