@abai/proxy 中文文档教程

发布于 3年前 浏览 24 更新于 3年前

@abai/proxy

所有数据都在没有不必要的缓冲的情况下即时处理并转发给客户端,使 unblocker 成为可用的最快的网络代理之一。

Method

该脚本使用“漂亮”的 url,除了看起来漂亮之外,还允许与相对路径的链接 无需修改即可工作。 (例如 )

除此之外,相对于根的链接 (例如 < a href="/path/to/file2.html">) 可以在不修改的情况下通过检查引荐来源网址和 307 将它们重定向到正确的方式来处理 在引用站点中的位置。 (尽管代理确实会尝试重写这些链接以避免重定向。)

通过调整其路径以包含代理的 URL 来代理 Cookie,并进行了一些额外的工作以确保它们 在切换协议或子域时保持不变。

Limitations

尽管代理适用于标准登录表单甚至大多数 AJAX 内容、OAuth 登录表单和任何使用 postMessage(Google、Facebook 等)不是 可能开箱即用。 这不是一个无法克服的问题,但它不是我希望在 短期。 欢迎补丁,包括进入主库的通用修复程序和特定于站点的修复程序 修复到示例文件夹中。

Example

const Proxy = require('@abai/proxy');

const express = require('express');
const app = express();

app.use(new Proxy({ prefix: '/proxy/' }));

app.get('/', (req, res) => {
  // ...
});

@abai/proxy

All data is processed and relayed to the client on the fly without unnecessary buffering, making unblocker one of the fastest web proxies available.

Method

The script uses "pretty" urls which, besides looking pretty, allow links with relative paths to just work without modification. (E.g. <a href="path/to/file2.html"></a>)

In addition to this, links that are relative to the root (E.g. <a href="/path/to/file2.html"></a>) can be handled without modification by checking the referrer and 307 redirecting them to the proper location in the referring site. (Although the proxy does attempt to rewrite these links to avoid the redirect.)

Cookies are proxied by adjusting their path to include the proxy's URL, and a bit of extra work is done to ensure they remain intact when switching protocols or subdomains.

Limitations

Although the proxy works well for standard login forms and even most AJAX content, OAuth login forms and anything that uses postMessage (Google, Facebook, etc.) are not likely to work out of the box. This is not an insurmountable issue, but it's not one that I expect to have fixed in the near term. Patches are welcome, including both a general-purpose fix to go into the main library, and site-specific fixes to go in the examples folder.

Example

const Proxy = require('@abai/proxy');

const express = require('express');
const app = express();

app.use(new Proxy({ prefix: '/proxy/' }));

app.get('/', (req, res) => {
  // ...
});
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文