0.21.0 • Published 1 month ago

@cellularjs/express-proxy v0.21.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 month ago

@cellularjs/express-proxy🐘

1. Example

Example 1: create a proxy for JSON api.

// $share/express-proxy/index.ts
import { expressProxy, InputTransform, OutputTransform  } from '@cellularjs/express-proxy';

const inputTransform: InputTransform = (req, proxyTo) => {
  return new IRQ(
    { to: proxyTo },
    { ...req.query, ...req.params, ...req.body },
  );
}

const outputTransform: OutputTransform = (expressCtx, cellularCtx) => {
  const { res } = expressCtx;
  const { irs } = cellularCtx;

  res
    .status(irs.header.status)
    .json(irs.body);
}

export const proxyTo = expressProxy(
  { inputTransform, outputTransform },
  localTransporter,
);
// iam/$gateway/http/index.ts
import { Router } from 'express';
import { proxyTo } from '$share/express-proxy';

export const iamRouter = Router();

iamRouter.post('/groups/add-user-to-group', proxyTo('IAM:AddUserToGroup'));

Example 2: override base proxy config for individual endpoint.

// iam/$gateway/http/index.ts
import { Router } from 'express';
import { proxyTo } from '$share/express-proxy';

export const iamRouter = Router();

iamRouter.get('/users', proxyTo('IAM:ListUsers', {
  outputTransform: (expressCtx, cellularCtx) => {
    const { res } = expressCtx;
    const { irs } = cellularCtx;

    res.send(`<pre>${JSON.stringify(irs.body)}</pre>`);
  },
}));
0.21.0

1 month ago

0.20.1

4 months ago

0.20.0

4 months ago

0.19.0

4 months ago

0.18.1

5 months ago

0.18.0

5 months ago

0.16.0

9 months ago

0.15.1

10 months ago

0.17.0

7 months ago

0.15.2

10 months ago

0.15.0

1 year ago

0.14.0

1 year ago

0.13.1

1 year ago

0.13.2

1 year ago

0.13.3

1 year ago

0.11.0

2 years ago

0.12.0

1 year ago

0.13.0

1 year ago

0.10.3

2 years ago

0.9.4

2 years ago

0.9.3

2 years ago

0.10.0

2 years ago

0.10.1

2 years ago

0.10.2

2 years ago

0.9.2

2 years ago

0.9.1

2 years ago

0.8.0-alpha.0

2 years ago

0.9.0

2 years ago

0.8.1

2 years ago

0.8.0

2 years ago

0.7.4

2 years ago

0.8.2

2 years ago

0.7.3

2 years ago

0.7.2

2 years ago

0.7.1

2 years ago

0.5.0

2 years ago

0.4.0

2 years ago

0.7.0

2 years ago

0.6.0

2 years ago

0.3.0

2 years ago