分享一个挂在worker上的多功能代理服务源码

自己搭了个newapi来集合一下api玩,当时选服务器选错了,gemini被地区限制了,然后又有佬友分享了个claude api,但是只支持流输出,不能放到newapi里面,所以让claude糊了这个程序,直接放cloudflare worker就可以用了,详细功能看下面介绍

下载链接

使用说明

程序使用一个全局配置对象 config 来管理各种设置:

const config = {
  hostSecurity: {
    enabled: true,
    status: false,
    whiteList: ['rfym.net', 'rfym.org'],
    blackList: ['baidu.com', 'taobao.com']
  },
  originSecurity: {
    enabled: true,
    status: false,
    whiteList: ['rfym.net', 'rfym.org'],
    blackList: ['baidu.com', 'taobao.com']
  }
}
  • hostSecurity: 控制允许访问的目标主机。
  • originSecurity: 控制允许的请求来源。
  • enabled: 是否启用安全检查。
  • status: true 表示使用白名单模式,false 表示使用黑名单模式。
  • whiteList: 允许的主机或来源列表。
  • blackList: 禁止的主机或来源列表。

使用方法

ServerProxy

直接代理请求到指定的目标 URL。

格式

/ServerProxy/[目标URL]

示例

https://your-worker.com/ServerProxy/https://api.example.com/data

这将代理请求到 https://api.example.com/data

UrlRedirect

通过 URL 参数重定向请求。

格式

/UrlRedirect/[编码后的目标URL]

示例

https://your-worker.com/UrlRedirect/[https%3A%2F%2Fwww.example.com%2Fpage]/http://domain.com/v1/chat

这将重定向请求到 https://www.example.com/page

HostProxy

替换请求的主机名进行代理。

格式

/HostProxy/[新主机名][原始路径]

示例

https://your-worker.com/HostProxy/[api.newdomain.com]http://domain.com/v1/users

这将把请求代理到 https://api.newdomain.com/v1/users

StreamRedirect

处理流式请求,使只支持流输出的openai api也能添加到newapi/oneapi。

格式

/StreamRedirect/目标URL

示例

POST https://your-worker.com/StreamRedirect/https://api.openai.com/v1/chat/completions

如果接口只支持流输出,则直接返回一个默认的响应体

PathRedirect

根据指定规则修改请求路径。

格式

/PathRedirect/[from]/[to]/目标URL

示例

https://your-worker.com/PathRedirect/[api]/[v2]http://example.com/api/data

这将把请求路径中的 “api” 替换为 “v2”,最终请求 http://example.com/v2/data

14 个赞

感谢佬友分享

1 个赞

没太明白,佬友的worker解决的是地区限制或者ip限制的问题吗?

1 个赞

mark一下 :tieba_013:

解决ip限制

好嘞,感谢佬友分享~ :xhs_014:

太强了大佬!

能登录youtube吗?

???不是看世界的代理服务