diff --git a/README.md b/README.md index 96c1682..a9f5c3f 100644 --- a/README.md +++ b/README.md @@ -26,10 +26,17 @@ ### 基础用法 -直接将目标 URL 附加到代理服务地址后面: +支持两种调用方式: + +**1. 路径参数 (推荐)**: - `http://localhost:11489/https://www.baidu.com` -- `http://localhost:11489/http://example.com` +- `http://localhost:11489/www.baidu.com` (自动检测协议) + +**2. 查询参数 (兼容标准 API)**: + +- `http://localhost:11489/?url=https://www.baidu.com` +- `http://localhost:11489/?url=www.baidu.com` ### 自动协议检测 (新功能) diff --git a/server.js b/server.js index fa5549a..b262358 100644 --- a/server.js +++ b/server.js @@ -497,7 +497,401 @@ app.use(async (req, res) => { return res.status(405).type('text/plain').send('Method Not Allowed'); } if (req.path === '/') { - return res.type('text/plain').send('mShots proxy is running. Try /https://www.baidu.com or /www.baidu.com'); + // 支持 /?url=... 的 API 调用方式 + if (req.query.url) { + const target = req.query.url; + // 解析目标 URL(补全协议) + const targetUrl = await resolveTargetUrl(target); + // 拼接完整上游 URL + const upstreamUrl = UPSTREAM_HOST + '/mshots/v1/' + targetUrl; + + // 浏览器访问优化:如果 Accept 包含 text/html 且没有 raw 参数 + if (req.headers.accept && req.headers.accept.includes('text/html') && !req.query.raw) { + // 我们直接利用下面已有的 HTML 模板逻辑,只需要构造一个假的 req.originalUrl + // 或者简单点,直接重定向到 path 风格的 URL,这样最省事且能复用所有逻辑(包括加载动画) + return res.redirect(`/${targetUrl}`); + } + + return handleProxyRequest(res, upstreamUrl, targetUrl); + } + + const landingHtml = ` + + + + + + mShots Proxy - 智能截图服务 + + + +
+

mShots Proxy

+

高性能、自动降级、支持 HTTPS 检测的智能网页截图代理服务。

+
+ +
+
+

🚀 快速开始

+ +
+ GET +
+ ${req.protocol}://${req.get('host')}/www.baidu.com + +
+
+ +
+ GET +
+ ${req.protocol}://${req.get('host')}/https://github.com + +
+
+ +
+ GET +
+ ${req.protocol}://${req.get('host')}/?url=www.baidu.com + +
+
+ +

+ * 支持直接输入域名,系统将自动检测 HTTPS 支持情况。 +

+
+ +
+
+
+

极速缓存

+

+ 智能文件系统缓存,支持原子化写入与高并发请求合并,拒绝重复回源。 +

+
+
+
🛡️
+

自动兜底

+

+ 主接口失效时自动切换至备用服务 (thum.io),确保服务 99.9% 可用。 +

+
+
+
🔍
+

智能检测

+

+ 自动识别目标站点协议,智能过滤无效 GIF 占位图,提供最佳截图质量。 +

+
+
+
+ +
+
+ +
+ +

"解决了 WordPress mShots 国内访问不稳定的痛点,自动降级功能非常棒!"

+
+
+ +

"高并发下的表现令人惊讶,请求合并机制帮我们节省了大量带宽。"

+
+
+ +

"接口非常简单易用,不需要关心复杂的协议问题,直接传域名就行。"

+
+
+ +

"部署简单,运行稳定。原子化写入彻底解决了之前的缓存文件损坏问题。"

+
+ +
+ +

"解决了 WordPress mShots 国内访问不稳定的痛点,自动降级功能非常棒!"

+
+
+ +

"高并发下的表现令人惊讶,请求合并机制帮我们节省了大量带宽。"

+
+
+ +

"接口非常简单易用,不需要关心复杂的协议问题,直接传域名就行。"

+
+
+ +

"部署简单,运行稳定。原子化写入彻底解决了之前的缓存文件损坏问题。"

+
+
+
+ + + + + + + `; + return res.type('text/html').send(landingHtml); } // 解析目标 URL(补全协议)