链接转换
把常用前端 CDN 链接转换为自己的代理地址。服务端会识别来源平台、按需跟随 30x 重定向,并以流式响应回源。
支持平台
输入链接的主机名决定回源站。jsDelivr 镜像与 StaticFile 旧域名会归一到规范源站。
| 平台 | 代理前缀 | 回源站点 |
|---|---|---|
| jsDelivr | /npm/gh/wp/combine |
cdn.jsdelivr.net |
| unpkg | /unpkg |
unpkg.com |
| jQuery CDN | /jquery |
code.jquery.com |
| cdnjs | /cdnjs |
cdnjs.cloudflare.com |
| cdnjs.snrat.com | /snrat |
cdnjs.snrat.com |
| Google Hosted Libraries | /google |
ajax.googleapis.com |
| BootCDN | /bootcdn |
cdn.bootcdn.net |
| StaticFile | /staticfile |
cdn.staticfile.net |
| 饿了么 CDN | /eleme |
npm.elemecdn.com |
| GitHub | /github |
github.com |
| GitHub Raw | /raw |
raw.githubusercontent.com |
| CNB | /cnb |
cnb.cool |
左右滑动查看全部
接口
转换接口只负责生成代理链接;访问生成的代理链接时,服务端才会向源站发起请求。以下示例使用当前代理域名 https://cdn.flowmoon.cn。
GET /api/convert
适合直接在浏览器、curl 或前端代码中调用,参数放在查询串中。
| 参数 | 必填 | 说明 |
|---|---|---|
url |
是 | 要转换的 CDN 链接。支持完整链接、// 开头与裸域名三种写法。 |
follow |
否 | 是否跟随 30x 并重新转换最终地址,默认 1;传 0 时只做纯字符串转换,不发起网络请求。 |
curl -G 'https://cdn.flowmoon.cn/api/convert' \
--data-urlencode 'url=https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css'
POST /api/convert
请求体必须是 JSON,并带上 content-type: application/json。follow 可选,默认 true。
curl -X POST 'https://cdn.flowmoon.cn/api/convert' \
-H 'content-type: application/json' \
-d '{"url":"//unpkg.com/[email protected]/umd/react.production.min.js","follow":false}'
响应示例
{
"input": "https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css",
"platform": "jsdelivr",
"platform_name": "jsDelivr",
"origin_url": "https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css",
"proxy_path": "/npm/[email protected]/dist/css/bootstrap.min.css",
"proxy_url": "https://cdn.flowmoon.cn/npm/[email protected]/dist/css/bootstrap.min.css",
"resolved": true,
"final_url": "https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
}
| 字段 | 类型 | 说明 |
|---|---|---|
input | string | 原始输入链接。 |
platform | string | 平台标识,例如 jsdelivr、unpkg、github-raw。 |
platform_name | string | 平台展示名称。 |
origin_url | string | 规范化后的源站地址,始终为 https。 |
proxy_path | string | 代理服务上的路径。 |
proxy_url | string | 可直接使用的完整代理链接。 |
resolved | boolean | 是否完成重定向解析。传 follow=0 时为 false。 |
final_url | string? | 跟随 30x 后的最终地址;未解析时省略。 |
redirects | string[]? | 重定向链;没有跳转时省略。 |
warning | string? | 解析失败或最终平台不受支持时的降级提示;此时仍会返回原始链接的转换结果。 |
错误响应
错误统一返回 {"error":"...","message":"..."},message 为可直接展示的中文说明。
{
"error": "unsupported_url",
"message": "无法识别的 CDN 平台: example.com。支持的平台: jsDelivr、unpkg、jQuery、cdnjs、..."
}
| 状态码 | error | 说明 |
|---|---|---|
| 400 | missing_url | 缺少 url 参数或请求体为空。 |
| 400 | unsupported_url | 无法识别平台,或链接格式不合法。 |
| 400 | invalid_follow | follow 参数无法解析。 |
| 400 | invalid_json | POST 请求体不是合法 JSON。 |
| 400 | invalid_upstream_url | 代理路径无法拼接为合法的源站地址。 |
| 404 | unsupported_path | 访问了无法识别的代理路径。 |
| 405 | method_not_allowed | 代理请求不是 GET 或 HEAD。 |
| 502 | upstream_error | 源站不可达、TLS 失败或响应异常。 |
| 502 | too_many_redirects | 源站重定向次数超过配置上限。 |
| 502 | blocked_redirect | 源站重定向到不受支持的域名,已拒绝跟随。 |
| 504 | upstream_timeout | 连接源站超时。 |
代理访问
拿到 proxy_url 后直接请求即可。代理只接受 GET 与 HEAD,并按平台前缀回源。
curl -I 'https://cdn.flowmoon.cn/npm/[email protected]/dist/css/bootstrap.min.css'
curl -H 'Range: bytes=0-99' \
'https://cdn.flowmoon.cn/raw/user/repo/main/file.js'
- 响应体以流式转发,不会先缓存整个文件。
- 保留
Content-Type、Content-Length、Cache-Control、ETag、Content-Range等必要响应头。 - 支持
Range与条件请求;上游的 4xx / 5xx 状态码和响应体会原样返回。 - 只跟随受支持平台及 GitHub / CNB 资源域名的 HTTPS 重定向,其他跳转返回 502
blocked_redirect。 - 不转发 Cookie、Authorization 等凭证头;跨域请求默认放开。
健康检查
GET /healthz 返回 {"status":"ok"},可用于负载均衡或监控探活。