# bin-gateway

> Binary Gateway Front End SDK

Latest version **0.0.1** (published 2022-02-25) · MIT license · 0 weekly downloads

## Install

```sh
npm install bin-gateway
pnpm add bin-gateway
yarn add bin-gateway
bun add bin-gateway
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.1 |
| Published | 2022-02-25 |
| First published | 2022-02-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 5 |
| Unpacked size | 29.3 KB |
| Known vulnerabilities | 0 (+11 in 1 direct dependencies) |
| Install scripts | no |
| Author | joye |
| Maintainers | joye61 |
| Keywords | bin, gateway |

## Links

- npm: https://www.npmjs.com/package/bin-gateway
- Repository: git@git.chelun.com:zhoujing2/bin-gateway
- npm.io page: https://npm.io/package/bin-gateway

## Dependencies (5)

- [pako](https://npm.io/package/pako.md) ^2.0.4
- [lodash](https://npm.io/package/lodash.md) ^4.17.21
- [protobufjs](https://npm.io/package/protobufjs.md) ^6.11.2
- [content-type](https://npm.io/package/content-type.md) ^1.0.4
- [set-cookie-parser](https://npm.io/package/set-cookie-parser.md) ^2.4.8

## Recent versions

- 0.0.1 (latest) — 2022-02-25

## README

# 二进制网关

前端二进制网关是一套通用代理，基于封装后的[Protocol Buffer](https://developers.google.com/protocol-buffers)消息协议，主要解决前端开发中面临的如下诸多问题：

1. 数据安全问题

    为了解决网络数据被劫持修改，爬虫抓取等问题：网关的所有消息交互都以`protobuf`二进制格式编码，在同时`protobuf`的基础上做了二次封装和压缩，没有任何工具或软件可以轻易解码，数据安全得到充分的保障

2. `CORS`跨域问题

    只要在网关的白名单（需要设置）之内，自动处理所有的跨域问题，一劳永逸的解决众多后端业务新域名所导致的跨域问题

3. `Cookie`问题

    全新浏览器针对`Cookie`的各种安全升级，如`SameSite`引入、跨域`Credentials`设置等，已经导致了无数的`Bug`类似：

    - `Cookie`毫无征兆的失效
    - 服务端明明已经下发了`Cookie`，请求时无法携带
    - 无法下发`Cookie`到指定域
    - ...


# 特色

1. **强大无比的跨域能力**，浏览器原生的网络请求都是受限于同源安全模型的，如`XMLHttpRequest`、`fetch`、`图片跨域`等，本网关提供的网络请求API是原生`fetch`的一个子集，兼容于原生`fetch`，但是却提供了WEB原生网络请求所不具备的**超强跨域能力**，如：
    
    - 你可以在网页上用网关的API在WEB上写爬虫程序，爬取其他站点的内容
    - 你可以在网页上通过网关的API，实现原来必须要借助服务器才能请求的API，如微信小程序的登录凭证API：[auth.code2Session](https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/login/auth.code2Session.html)


2. 远超`json`或`xml`数据格式的编解码性能：

    关于`protobuf`的编解码性能，网络上有很多文章，请自行查阅

3. 非破坏兼容性：

    - 由于网关以中间层的形式提供，在接收到前端小消息后会自动将消息解码为原来的数据格式，所以不需要原来的服务器逻辑做任何代码上的变更
    - 由于网关API签名尽可能的兼容于`fetch`，前端也几乎不需要做什么代码变更，只需要引入对应的库而已

---
_Source: https://npm.io/package/bin-gateway · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
