From 72bb706023c49a8969015dd1a546ab46fb38b84c Mon Sep 17 00:00:00 2001
From: Mrx <18278715334@163.com>
Date: Sat, 28 Feb 2026 12:45:13 +0800
Subject: [PATCH] up seo
---
public/seo-templates/agent.html | 79 ++++
public/seo-templates/example.html | 79 ++++
public/seo-templates/help-guide.html | 79 ++++
public/seo-templates/help.html | 79 ++++
public/seo-templates/index.html | 79 ++++
.../inquire-category-lawsuit.html | 79 ++++
.../inquire-category-marriageStatus.html | 79 ++++
.../inquire-category-vehicle.html | 79 ++++
public/seo-templates/inquire-marriage.html | 79 ++++
public/seo-templates/inquire.html | 79 ++++
public/seo-templates/service.html | 79 ++++
server/README-SEO.md | 351 ++++++++++++++++++
server/crawler-detector.js | 170 +++++++++
server/generate-seo-templates.cjs | 220 +++++++++++
server/middleware.js | 175 +++++++++
server/nginx-www.tianyuandb.com.conf | 141 +++++++
server/package.json | 27 ++
server/server-example-express.js | 36 ++
server/test-crawler-detection.js | 112 ++++++
server/test-seo.js | 178 +++++++++
server/如何检测.md | 211 +++++++++++
server/宝塔Nginx-SEO部署说明.md | 56 +++
server/部署说明-tianyuandb.md | 50 +++
src/components/BindPhoneDialog.vue | 39 +-
src/components/RealNameAuthDialog.vue | 29 +-
25 files changed, 2633 insertions(+), 31 deletions(-)
create mode 100644 public/seo-templates/agent.html
create mode 100644 public/seo-templates/example.html
create mode 100644 public/seo-templates/help-guide.html
create mode 100644 public/seo-templates/help.html
create mode 100644 public/seo-templates/index.html
create mode 100644 public/seo-templates/inquire-category-lawsuit.html
create mode 100644 public/seo-templates/inquire-category-marriageStatus.html
create mode 100644 public/seo-templates/inquire-category-vehicle.html
create mode 100644 public/seo-templates/inquire-marriage.html
create mode 100644 public/seo-templates/inquire.html
create mode 100644 public/seo-templates/service.html
create mode 100644 server/README-SEO.md
create mode 100644 server/crawler-detector.js
create mode 100644 server/generate-seo-templates.cjs
create mode 100644 server/middleware.js
create mode 100644 server/nginx-www.tianyuandb.com.conf
create mode 100644 server/package.json
create mode 100644 server/server-example-express.js
create mode 100644 server/test-crawler-detection.js
create mode 100644 server/test-seo.js
create mode 100644 server/如何检测.md
create mode 100644 server/宝塔Nginx-SEO部署说明.md
create mode 100644 server/部署说明-tianyuandb.md
diff --git a/public/seo-templates/agent.html b/public/seo-templates/agent.html
new file mode 100644
index 0000000..89e3160
--- /dev/null
+++ b/public/seo-templates/agent.html
@@ -0,0 +1,79 @@
+
+
+
+
+
天远查代理 - 免费开通代理权限 | 大数据风险报告代理
+
+
正在跳转到完整版网站...
+
如果浏览器没有自动跳转,请 点击这里
+
+
天远查代理平台,免费开通代理权限,享受大数据风险报告查询服务代理收益。专业的大数据风险报告、婚姻查询、个人信用评估等服务的代理合作。
+
+ 关于天远查
+ 天远查官网(TianYuanCha)聚合官方公示数据,专注于商业安全与资产背调。提供企业工商画像、婚姻状态关联风险、司法涉诉筛查及配偶债务核验。
+
+
+ 核心服务
+
+ - 司法涉诉核验与法律诉讼记录
+ - 婚前背景核验与婚姻关联风险筛查
+ - 车辆档案报告与二手车车况检测
+ - 个人婚姻关联风险核验
+ - 多场景数据核验服务
+
+
+
+
+
\ No newline at end of file
diff --git a/public/seo-templates/example.html b/public/seo-templates/example.html
new file mode 100644
index 0000000..e9239aa
--- /dev/null
+++ b/public/seo-templates/example.html
@@ -0,0 +1,79 @@
+
+
+
+
+
示例报告 - 天远查报告展示 | 大数据风险报告样例
+
+
正在跳转到完整版网站...
+
如果浏览器没有自动跳转,请 点击这里
+
+
天远查示例报告展示,包含大数据风险报告、婚姻状况查询、个人信用评估等服务的报告样例,让用户了解报告内容和格式。
+
+ 关于天远查
+ 天远查官网(TianYuanCha)聚合官方公示数据,专注于商业安全与资产背调。提供企业工商画像、婚姻状态关联风险、司法涉诉筛查及配偶债务核验。
+
+
+ 核心服务
+
+ - 司法涉诉核验与法律诉讼记录
+ - 婚前背景核验与婚姻关联风险筛查
+ - 车辆档案报告与二手车车况检测
+ - 个人婚姻关联风险核验
+ - 多场景数据核验服务
+
+
+
+
+
\ No newline at end of file
diff --git a/public/seo-templates/help-guide.html b/public/seo-templates/help-guide.html
new file mode 100644
index 0000000..ec99a5b
--- /dev/null
+++ b/public/seo-templates/help-guide.html
@@ -0,0 +1,79 @@
+
+
+
+
+
使用指南 - 天远查操作教程 | 功能说明
+
+
正在跳转到完整版网站...
+
如果浏览器没有自动跳转,请 点击这里
+
+
天远查详细使用指南,包含各功能模块的操作教程、功能说明、注意事项等,让用户快速上手使用。
+
+ 关于天远查
+ 天远查官网(TianYuanCha)聚合官方公示数据,专注于商业安全与资产背调。提供企业工商画像、婚姻状态关联风险、司法涉诉筛查及配偶债务核验。
+
+
+ 核心服务
+
+ - 司法涉诉核验与法律诉讼记录
+ - 婚前背景核验与婚姻关联风险筛查
+ - 车辆档案报告与二手车车况检测
+ - 个人婚姻关联风险核验
+ - 多场景数据核验服务
+
+
+
+
+
\ No newline at end of file
diff --git a/public/seo-templates/help.html b/public/seo-templates/help.html
new file mode 100644
index 0000000..b716a3f
--- /dev/null
+++ b/public/seo-templates/help.html
@@ -0,0 +1,79 @@
+
+
+
+
+
帮助中心 - 天远查使用指南 | 常见问题解答
+
+
正在跳转到完整版网站...
+
如果浏览器没有自动跳转,请 点击这里
+
+
天远查帮助中心,提供详细的使用指南、常见问题解答、操作教程等,帮助用户更好地使用大数据风险报告查询服务。
+
+ 关于天远查
+ 天远查官网(TianYuanCha)聚合官方公示数据,专注于商业安全与资产背调。提供企业工商画像、婚姻状态关联风险、司法涉诉筛查及配偶债务核验。
+
+
+ 核心服务
+
+ - 司法涉诉核验与法律诉讼记录
+ - 婚前背景核验与婚姻关联风险筛查
+ - 车辆档案报告与二手车车况检测
+ - 个人婚姻关联风险核验
+ - 多场景数据核验服务
+
+
+
+
+
\ No newline at end of file
diff --git a/public/seo-templates/index.html b/public/seo-templates/index.html
new file mode 100644
index 0000000..9d5f1fe
--- /dev/null
+++ b/public/seo-templates/index.html
@@ -0,0 +1,79 @@
+
+
+
+
+
天远查官网_企业与婚姻关联风险核验_综合履约背景核验
+
+
正在跳转到完整版网站...
+
如果浏览器没有自动跳转,请 点击这里
+
+
天远查官网(TianYuanCha)聚合官方公示数据,专注于商业安全与资产背调。提供企业工商画像、婚姻状态关联风险、司法涉诉筛查及配偶债务核验。数据实时同步,助您精准规避投资、交易及家庭结合中的经济与法律风险。
+
+ 关于天远查
+ 天远查官网(TianYuanCha)聚合官方公示数据,专注于商业安全与资产背调。提供企业工商画像、婚姻状态关联风险、司法涉诉筛查及配偶债务核验。
+
+
+ 核心服务
+
+ - 司法涉诉核验与法律诉讼记录
+ - 婚前背景核验与婚姻关联风险筛查
+ - 车辆档案报告与二手车车况检测
+ - 个人婚姻关联风险核验
+ - 多场景数据核验服务
+
+
+
+
+
\ No newline at end of file
diff --git a/public/seo-templates/inquire-category-lawsuit.html b/public/seo-templates/inquire-category-lawsuit.html
new file mode 100644
index 0000000..c244a70
--- /dev/null
+++ b/public/seo-templates/inquire-category-lawsuit.html
@@ -0,0 +1,79 @@
+
+
+
+
+
司法涉诉核验_个人及企业法律诉讼记录_履约风险评估_天远查
+
+
正在跳转到完整版网站...
+
如果浏览器没有自动跳转,请 点击这里
+
+
天远查司法风险检测中心,聚合全国法院公开公示数据。一键筛查开庭公告、裁判文书、立案信息及执行记录。帮助用户快速识别法律纠纷隐患,全方位扫除合作盲区。
+
+ 关于天远查
+ 天远查官网(TianYuanCha)聚合官方公示数据,专注于商业安全与资产背调。提供企业工商画像、婚姻状态关联风险、司法涉诉筛查及配偶债务核验。
+
+
+ 核心服务
+
+ - 司法涉诉核验与法律诉讼记录
+ - 婚前背景核验与婚姻关联风险筛查
+ - 车辆档案报告与二手车车况检测
+ - 个人婚姻关联风险核验
+ - 多场景数据核验服务
+
+
+
+
+
\ No newline at end of file
diff --git a/public/seo-templates/inquire-category-marriageStatus.html b/public/seo-templates/inquire-category-marriageStatus.html
new file mode 100644
index 0000000..9152550
--- /dev/null
+++ b/public/seo-templates/inquire-category-marriageStatus.html
@@ -0,0 +1,79 @@
+
+
+
+
+
个人婚姻关联风险核验_家庭背景合规报告_天远查
+
+
正在跳转到完整版网站...
+
如果浏览器没有自动跳转,请 点击这里
+
+
天远查提供基于大数据的婚姻关联风险评估。通过分析司法文书及公开社会关系,辅助判断目标的真实家庭状况与情感履历。合法合规,保障知情权。
+
+ 关于天远查
+ 天远查官网(TianYuanCha)聚合官方公示数据,专注于商业安全与资产背调。提供企业工商画像、婚姻状态关联风险、司法涉诉筛查及配偶债务核验。
+
+
+ 核心服务
+
+ - 司法涉诉核验与法律诉讼记录
+ - 婚前背景核验与婚姻关联风险筛查
+ - 车辆档案报告与二手车车况检测
+ - 个人婚姻关联风险核验
+ - 多场景数据核验服务
+
+
+
+
+
\ No newline at end of file
diff --git a/public/seo-templates/inquire-category-vehicle.html b/public/seo-templates/inquire-category-vehicle.html
new file mode 100644
index 0000000..97e11ef
--- /dev/null
+++ b/public/seo-templates/inquire-category-vehicle.html
@@ -0,0 +1,79 @@
+
+
+
+
+
车辆档案报告_二手车车况与产权风险检测_机动车报告_天远查
+
+
正在跳转到完整版网站...
+
如果浏览器没有自动跳转,请 点击这里
+
+
天远查车辆数据中心,让车辆交易更透明。支持通过车牌号或VIN码,核验车辆的初次登记信息、抵押查封状态、事故维修记录及产权属性。数据同步权威行业系统,精准识别问题车。
+
+ 关于天远查
+ 天远查官网(TianYuanCha)聚合官方公示数据,专注于商业安全与资产背调。提供企业工商画像、婚姻状态关联风险、司法涉诉筛查及配偶债务核验。
+
+
+ 核心服务
+
+ - 司法涉诉核验与法律诉讼记录
+ - 婚前背景核验与婚姻关联风险筛查
+ - 车辆档案报告与二手车车况检测
+ - 个人婚姻关联风险核验
+ - 多场景数据核验服务
+
+
+
+
+
\ No newline at end of file
diff --git a/public/seo-templates/inquire-marriage.html b/public/seo-templates/inquire-marriage.html
new file mode 100644
index 0000000..940bb76
--- /dev/null
+++ b/public/seo-templates/inquire-marriage.html
@@ -0,0 +1,79 @@
+
+
+
+
+
婚前背景核验_婚姻关联司法风险筛查_情感综合保障_天远查
+
+
正在跳转到完整版网站...
+
如果浏览器没有自动跳转,请 点击这里
+
+
天远查婚恋风险报告为您提供深度的背景核实服务。基于合法公开数据,排查对象的重婚司法记录、家庭暴力涉诉历史、潜在债务风险及不良嗜好风险。拒绝盲目信任,用数据守护您的情感与财产安全。
+
+ 关于天远查
+ 天远查官网(TianYuanCha)聚合官方公示数据,专注于商业安全与资产背调。提供企业工商画像、婚姻状态关联风险、司法涉诉筛查及配偶债务核验。
+
+
+ 核心服务
+
+ - 司法涉诉核验与法律诉讼记录
+ - 婚前背景核验与婚姻关联风险筛查
+ - 车辆档案报告与二手车车况检测
+ - 个人婚姻关联风险核验
+ - 多场景数据核验服务
+
+
+
+
+
\ No newline at end of file
diff --git a/public/seo-templates/inquire.html b/public/seo-templates/inquire.html
new file mode 100644
index 0000000..7355511
--- /dev/null
+++ b/public/seo-templates/inquire.html
@@ -0,0 +1,79 @@
+
+
+
+
+
核验工具多场景数据核验服务天远查
+
+
正在跳转到完整版网站...
+
如果浏览器没有自动跳转,请 点击这里
+
+
提供车辆、企业、个人等多场景核验,包括状态、信用、身份等查询,权威高效,保护隐私。
+
+ 关于天远查
+ 天远查官网(TianYuanCha)聚合官方公示数据,专注于商业安全与资产背调。提供企业工商画像、婚姻状态关联风险、司法涉诉筛查及配偶债务核验。
+
+
+ 核心服务
+
+ - 司法涉诉核验与法律诉讼记录
+ - 婚前背景核验与婚姻关联风险筛查
+ - 车辆档案报告与二手车车况检测
+ - 个人婚姻关联风险核验
+ - 多场景数据核验服务
+
+
+
+
+
\ No newline at end of file
diff --git a/public/seo-templates/service.html b/public/seo-templates/service.html
new file mode 100644
index 0000000..1615188
--- /dev/null
+++ b/public/seo-templates/service.html
@@ -0,0 +1,79 @@
+
+
+
+
+
客服中心 - 天远查在线客服 | 技术支持
+
+
正在跳转到完整版网站...
+
如果浏览器没有自动跳转,请 点击这里
+
+
天远查客服中心,提供在线客服支持、技术咨询、问题反馈等服务,确保用户获得及时有效的帮助。
+
+ 关于天远查
+ 天远查官网(TianYuanCha)聚合官方公示数据,专注于商业安全与资产背调。提供企业工商画像、婚姻状态关联风险、司法涉诉筛查及配偶债务核验。
+
+
+ 核心服务
+
+ - 司法涉诉核验与法律诉讼记录
+ - 婚前背景核验与婚姻关联风险筛查
+ - 车辆档案报告与二手车车况检测
+ - 个人婚姻关联风险核验
+ - 多场景数据核验服务
+
+
+
+
+
\ No newline at end of file
diff --git a/server/README-SEO.md b/server/README-SEO.md
new file mode 100644
index 0000000..fe17b4f
--- /dev/null
+++ b/server/README-SEO.md
@@ -0,0 +1,351 @@
+# SPA SEO 优化解决方案
+
+## 📋 方案概述
+
+针对 SPA 应用 SEO 问题,采用**爬虫检测 + 静态 HTML 回退**方案:
+
+1. **爬虫检测**:识别搜索引擎爬虫(百度、Google、必应、搜狗等)
+2. **静态 HTML**:为爬虫提供预渲染的 HTML 模板,包含完整 TDK、OG、canonical、结构化数据
+3. **正常用户**:继续使用 SPA,体验不受影响
+
+**配置统一**:服务端 SEO 模板内容与前端 `src/composables/useSEO.js` 保持一致(标题、描述、关键词、域名),域名默认为 `https://www.tianyuancha.cn`(天远查)。可通过环境变量 `SEO_BASE_URL` 覆盖。
+
+## 🏗️ 项目结构
+
+```
+server/
+├── crawler-detector.js # 爬虫检测模块
+├── middleware.js # SEO 中间件(Express/Koa),路由与 useSEO.js 一致
+├── generate-seo-templates.cjs # SEO 模板生成器(与 useSEO.js 同步)
+├── server-example-express.js # Express 服务器示例
+├── nginx-www.tianyuandb.com.conf # 天远数据 Nginx 配置(tianyuandb.com)
+├── nginx-www.xingfucha.cn.conf # 幸福查 Nginx 配置示例
+├── nginx-seo-location-替换片段.conf # Nginx SEO 片段
+├── test-seo.js # SEO 端到端检测脚本
+└── README-SEO.md # 本文档
+
+public/
+└── seo-templates/ # SEO 静态模板目录(运行 generate 后生成)
+ ├── index.html
+ ├── inquire.html
+ ├── inquire-category-lawsuit.html
+ ├── inquire-category-vehicle.html
+ ├── inquire-category-marriageStatus.html
+ ├── inquire-marriage.html
+ ├── agent.html
+ ├── help.html
+ ├── help-guide.html
+ ├── example.html
+ ├── service.html
+ └── ...
+```
+
+## 🚀 快速开始
+
+### 步骤1:生成 SEO 模板
+
+```bash
+cd server
+node generate-seo-templates.cjs
+# 或 npm run generate
+```
+
+这会在 `public/seo-templates/` 下生成所有页面的静态 HTML 模板,内容与 `src/composables/useSEO.js` 一致。
+
+### 步骤2:集成到你的服务器
+
+#### 选项A:使用Express服务器
+
+```javascript
+const express = require('express')
+const SEOMiddleware = require('./server/middleware')
+
+const app = express()
+
+// 初始化SEO中间件
+const seoMiddleware = new SEOMiddleware({
+ templateDir: path.join(__dirname, 'public/seo-templates'),
+ debug: true // 开发环境开启调试日志
+})
+
+// 应用SEO中间件(必须在静态文件服务之前)
+app.use(seoMiddleware.express())
+
+// 静态文件服务
+app.use(express.static(path.join(__dirname, 'dist')))
+
+// SPA路由处理
+app.get('*', (req, res) => {
+ res.sendFile(path.join(__dirname, 'dist/index.html'))
+})
+```
+
+#### 选项B:使用 Nginx
+
+- 天远数据站点:参考 `server/nginx-www.tianyuandb.com.conf`,将 `root` 和 `server_name`、证书路径改为你的服务器路径。
+- 幸福查站点:参考 `server/nginx-www.xingfucha.cn.conf`。
+- 部署时把 `public/seo-templates/` 整目录上传到服务器 `root` 下的 `seo-templates/`。
+
+```bash
+# 复制并修改配置
+cp server/nginx-www.tianyuandb.com.conf /etc/nginx/sites-available/zhinengcha
+nano /etc/nginx/sites-available/zhinengcha # 修改 root、证书等
+
+# 启用并重载
+ln -s /etc/nginx/sites-available/zhinengcha /etc/nginx/sites-enabled/
+nginx -t && systemctl restart nginx
+```
+
+#### 选项C:使用Koa
+
+```javascript
+const Koa = require('koa')
+const serve = require('koa-static')
+const SEOMiddleware = require('./server/middleware')
+
+const app = new Koa()
+
+// 应用SEO中间件
+const seoMiddleware = new SEOMiddleware({
+ templateDir: path.join(__dirname, 'public/seo-templates'),
+ debug: true
+})
+
+app.use(seoMiddleware.koa())
+
+// 静态文件服务
+app.use(serve(path.join(__dirname, 'dist')))
+
+app.listen(3000)
+```
+
+### 步骤3:测试爬虫检测
+
+```bash
+# 模拟百度爬虫
+curl -A "Baiduspider" http://localhost:3000/
+
+# 模拟Google爬虫
+curl -A "Googlebot/2.1" http://localhost:3000/
+
+# 模拟普通用户
+curl http://localhost:3000/
+```
+
+## 🔧 配置说明
+
+### 爬虫检测器配置
+
+`crawler-detector.js` 包含以下爬虫识别:
+
+- **中文搜索引擎**:百度、360、搜狗、必应、有道、搜搜、头条搜索
+- **国际搜索引擎**:Google、Bing、Yahoo
+- **社交媒体爬虫**:Facebook、Twitter、LinkedIn、WhatsApp等
+
+你可以根据需要添加或修改爬虫模式:
+
+```javascript
+// 在crawler-detector.js中添加新的爬虫模式
+this.crawlerPatterns.push('your-custom-bot')
+```
+
+### 路由到模板映射
+
+在 `middleware.js` 中配置路由与模板的对应关系:
+
+```javascript
+this.routeTemplateMap = {
+ '/': 'index.html',
+ '/agent': 'agent.html',
+ // 添加新的路由映射
+ '/new-route': 'new-template.html'
+}
+```
+
+### 模板生成配置
+
+**推荐**:页面 SEO 以 `src/composables/useSEO.js` 为唯一来源;修改标题/描述/关键词时只改 `useSEO.js` 中的 `routeConfigs`,然后同步到服务端:
+
+- 在 `server/generate-seo-templates.cjs` 的 `pageSEOConfigs` 中保持与 `useSEO.js` 一致(含新增路由与 `BASE_URL`)。
+- 在 `server/middleware.js` 的 `routeTemplateMap` 中为新路由添加映射。
+- 若用 Nginx,在对应 conf 的 `$seo_file` 中增加 `if ($uri = '/新路径') { set $seo_file 新模板.html; }`。
+
+新增页面示例(`generate-seo-templates.cjs`):
+
+```javascript
+'new-template.html': {
+ title: '页面标题',
+ description: '页面描述',
+ keywords: '关键词1,关键词2',
+ url: 'https://www.tianyuandb.com/new-route'
+}
+```
+
+## 📝 自定义模板
+
+### 修改模板样式
+
+编辑 `generate-seo-templates.js` 中的 `generateHTMLTemplate` 函数:
+
+```javascript
+function generateHTMLTemplate(config) {
+ return `
+
+
+
+
+
+
+
+
+ `
+}
+```
+
+### 添加结构化数据
+
+模板已包含基本的结构化数据(JSON-LD格式),如需扩展:
+
+```javascript
+const structuredData = {
+ "@context": "https://schema.org",
+ "@type": "WebPage",
+ // 添加更多字段
+ "breadcrumb": {
+ "@type": "BreadcrumbList",
+ "itemListElement": [...]
+ }
+}
+```
+
+## 🧪 验证SEO效果
+
+### 使用在线工具
+
+1. **百度资源平台**:https://ziyuan.baidu.com/
+2. **Google Search Console**:https://search.google.com/search-console
+3. **必应网站管理员工具**:https://www.bing.com/webmasters
+
+### 使用命令行工具与检测脚本
+
+```bash
+# 本地/线上 SEO 检测(会请求爬虫 UA 与普通 UA)
+cd server
+SEO_TEST_URL=http://localhost:3000 node test-seo.js
+# 或线上:SEO_TEST_URL=https://www.tianyuandb.com node test-seo.js
+```
+
+```bash
+# 查看爬虫看到的标题
+curl -s -A "Baiduspider/2.0" https://www.tianyuandb.com/ | grep -o '
+
${escapeAttr(title)}
+
+
正在跳转到完整版网站...
+
如果浏览器没有自动跳转,请 点击这里
+
+
${escapeAttr(description)}
+
+ 关于天远查
+ 天远查官网(TianYuanCha)聚合官方公示数据,专注于商业安全与资产背调。提供企业工商画像、婚姻状态关联风险、司法涉诉筛查及配偶债务核验。
+
+
+ 核心服务
+
+ - 司法涉诉核验与法律诉讼记录
+ - 婚前背景核验与婚姻关联风险筛查
+ - 车辆档案报告与二手车车况检测
+ - 个人婚姻关联风险核验
+ - 多场景数据核验服务
+
+
+
+
+`
+}
+
+function main() {
+ const outputDir = path.join(__dirname, '../public/seo-templates')
+
+ if (!fs.existsSync(outputDir)) {
+ fs.mkdirSync(outputDir, { recursive: true })
+ console.log(`✓ 创建模板目录: ${outputDir}`)
+ }
+
+ let successCount = 0
+ Object.entries(pageSEOConfigs).forEach(([filename, config]) => {
+ const htmlContent = generateHTMLTemplate(config)
+ const filePath = path.join(outputDir, filename)
+ fs.writeFileSync(filePath, htmlContent, 'utf-8')
+ console.log(`✓ 生成模板: ${filename}`)
+ successCount++
+ })
+
+ console.log(`\n✓ 成功生成 ${successCount} 个 SEO 模板文件`)
+ console.log(`📁 模板目录: ${outputDir}`)
+ console.log(`💡 配置与 useSEO.js 一致,当前域名: ${BASE_URL}`)
+}
+
+main()
diff --git a/server/middleware.js b/server/middleware.js
new file mode 100644
index 0000000..e284242
--- /dev/null
+++ b/server/middleware.js
@@ -0,0 +1,175 @@
+/**
+ * SEO中间件
+ * 用于在Node.js服务器中检测爬虫并返回静态HTML
+ */
+
+const fs = require('fs')
+const path = require('path')
+const CrawlerDetector = require('./crawler-detector')
+
+class SEOMiddleware {
+ constructor(options = {}) {
+ this.detector = new CrawlerDetector()
+ this.templateDir = options.templateDir || path.join(__dirname, '../public/seo-templates')
+ this.defaultTemplate = options.defaultTemplate || 'index.html'
+ this.fallbackToSPA = options.fallbackToSPA !== false
+ this.debug = options.debug || false
+
+ // 路由到模板的映射(与 useSEO.js 及 generate-seo-templates.cjs 保持一致;子路径放前面以优先精确匹配)
+ this.routeTemplateMap = {
+ '/': 'index.html',
+ '/inquire/category/lawsuit': 'inquire-category-lawsuit.html',
+ '/inquire/category/vehicle': 'inquire-category-vehicle.html',
+ '/inquire/category/marriageStatus': 'inquire-category-marriageStatus.html',
+ '/inquire/marriage': 'inquire-marriage.html',
+ '/inquire': 'inquire.html',
+ '/agent': 'agent.html',
+ '/help/guide': 'help-guide.html',
+ '/help': 'help.html',
+ '/example': 'example.html',
+ '/service': 'service.html'
+ }
+
+ // 初始化模板缓存
+ this.templateCache = new Map()
+ this.cacheTemplates()
+ }
+
+ /**
+ * 缓存所有模板文件
+ */
+ cacheTemplates() {
+ try {
+ if (!fs.existsSync(this.templateDir)) {
+ console.warn(`[SEOMiddleware] 模板目录不存在: ${this.templateDir}`)
+ return
+ }
+
+ const files = fs.readdirSync(this.templateDir)
+ files.forEach(file => {
+ const filePath = path.join(this.templateDir, file)
+ if (fs.statSync(filePath).isFile()) {
+ this.templateCache.set(file, fs.readFileSync(filePath, 'utf-8'))
+ if (this.debug) {
+ console.log(`[SEOMiddleware] 已缓存模板: ${file}`)
+ }
+ }
+ })
+
+ console.log(`[SEOMiddleware] 已缓存 ${this.templateCache.size} 个模板文件`)
+ } catch (error) {
+ console.error('[SEOMiddleware] 缓存模板失败:', error)
+ }
+ }
+
+ /**
+ * 获取对应的模板文件名
+ * @param {String} path - 请求路径
+ * @returns {String} 模板文件名
+ */
+ getTemplatePath(requestPath) {
+ // 完全匹配
+ if (this.routeTemplateMap[requestPath]) {
+ return this.routeTemplateMap[requestPath]
+ }
+
+ // 模糊匹配(处理动态路由)
+ const matchedKey = Object.keys(this.routeTemplateMap).find(route => {
+ return requestPath.startsWith(route)
+ })
+
+ return matchedKey ? this.routeTemplateMap[matchedKey] : this.defaultTemplate
+ }
+
+ /**
+ * 获取模板内容
+ * @param {String} templateName - 模板文件名
+ * @returns {String|null} 模板内容
+ */
+ getTemplate(templateName) {
+ // 首先尝试缓存
+ let content = this.templateCache.get(templateName)
+
+ // 如果缓存中没有,尝试从磁盘读取
+ if (!content) {
+ try {
+ const filePath = path.join(this.templateDir, templateName)
+ if (fs.existsSync(filePath)) {
+ content = fs.readFileSync(filePath, 'utf-8')
+ this.templateCache.set(templateName, content)
+ }
+ } catch (error) {
+ console.error(`[SEOMiddleware] 读取模板失败: ${templateName}`, error)
+ }
+ }
+
+ return content || null
+ }
+
+ /**
+ * Express中间件
+ */
+ express() {
+ return (req, res, next) => {
+ // 检测是否为爬虫
+ if (this.detector.isCrawler(req)) {
+ const templateName = this.getTemplatePath(req.path)
+ const template = this.getTemplate(templateName)
+
+ if (template) {
+ // 设置响应头
+ res.setHeader('Content-Type', 'text/html; charset=utf-8')
+ res.setHeader('X-SEOMiddleware', 'prerendered')
+
+ // 返回静态HTML
+ if (this.debug) {
+ console.log(`[SEOMiddleware] 返回SEO模板: ${templateName} for ${req.path}`)
+ }
+
+ return res.send(template)
+ }
+ }
+
+ // 不是爬虫或模板不存在,继续处理SPA
+ next()
+ }
+ }
+
+ /**
+ * Koa中间件
+ */
+ koa() {
+ return async (ctx, next) => {
+ // 检测是否为爬虫
+ if (this.detector.isCrawler(ctx.req)) {
+ const templateName = this.getTemplatePath(ctx.path)
+ const template = this.getTemplate(templateName)
+
+ if (template) {
+ ctx.type = 'text/html; charset=utf-8'
+ ctx.set('X-SEOMiddleware', 'prerendered')
+
+ if (this.debug) {
+ console.log(`[SEOMiddleware] 返回SEO模板: ${templateName} for ${ctx.path}`)
+ }
+
+ ctx.body = template
+ return
+ }
+ }
+
+ await next()
+ }
+ }
+
+ /**
+ * 重新加载模板缓存
+ */
+ reloadCache() {
+ this.templateCache.clear()
+ this.cacheTemplates()
+ console.log('[SEOMiddleware] 模板缓存已重新加载')
+ }
+}
+
+module.exports = SEOMiddleware
diff --git a/server/nginx-www.tianyuandb.com.conf b/server/nginx-www.tianyuandb.com.conf
new file mode 100644
index 0000000..adc20d3
--- /dev/null
+++ b/server/nginx-www.tianyuandb.com.conf
@@ -0,0 +1,141 @@
+# 天远数据 - www.tianyuandb.com 完整配置(含 SEO 爬虫检测)
+# 使用前请将 public/seo-templates 上传到服务器:/www/sites/www.tianyuandb.com/index/seo-templates/
+# 生成 tianyuandb 用模板:SEO_BASE_URL=https://www.tianyuandb.com node generate-seo-templates.cjs
+
+server {
+ listen 80;
+ listen 443 ssl http2;
+ server_name www.tianyuandb.com tianyuandb.com;
+ index index.php index.html index.htm default.php default.htm default.html;
+ root /www/sites/www.tianyuandb.com/index;
+
+ # ========== SEO 爬虫检测与模板映射(请勿删除) ==========
+ set $is_crawler 0;
+ if ($http_user_agent ~* "baiduspider|baiduspider-mobile|baiduspider-image|baiduspider-video|baiduspider-news|baiduboxapp") {
+ set $is_crawler 1;
+ }
+ if ($http_user_agent ~* "googlebot|googlebot-image|googlebot-news|googlebot-mobile|googlebot-video|google-web-snippet") {
+ set $is_crawler 1;
+ }
+ if ($http_user_agent ~* "bingbot|msnbot") {
+ set $is_crawler 1;
+ }
+ if ($http_user_agent ~* "360spider|soha-agent|haosouspider") {
+ set $is_crawler 1;
+ }
+ if ($http_user_agent ~* "sogou spider|sogou news spider|sogou orion spider|sogou-blog") {
+ set $is_crawler 1;
+ }
+ if ($http_user_agent ~* "slurp|sosospider|sosoimagespider|youdaobot|yodaobot") {
+ set $is_crawler 1;
+ }
+ if ($http_user_agent ~* "bytedance-spider|toutiaospider") {
+ set $is_crawler 1;
+ }
+ if ($http_user_agent ~* "facebookexternalhit|facebookcatalog|twitterbot|linkedinbot|whatsapp|telegrambot|viber|line") {
+ set $is_crawler 1;
+ }
+
+ set $seo_file index.html;
+ if ($uri = '/') { set $seo_file index.html; }
+ if ($uri = '/historyQuery') { set $seo_file historyQuery.html; }
+ if ($uri = '/agent') { set $seo_file agent.html; }
+ if ($uri = '/agent/promote') { set $seo_file agent-promote.html; }
+ if ($uri = '/agent/invitation') { set $seo_file agent-invitation.html; }
+ if ($uri = '/help') { set $seo_file help.html; }
+ if ($uri = '/help/guide') { set $seo_file help-guide.html; }
+ if ($uri = '/example') { set $seo_file example.html; }
+ if ($uri = '/service') { set $seo_file service.html; }
+ if ($uri = '/inquire/personalData') { set $seo_file inquire-personalData.html; }
+ if ($uri = '/inquire/companyinfo') { set $seo_file inquire-companyinfo.html; }
+ if ($uri = '/inquire/preloanbackgroundcheck') { set $seo_file inquire-preloanbackgroundcheck.html; }
+ if ($uri = '/inquire/marriage') { set $seo_file inquire-marriage.html; }
+ if ($uri = '/inquire/backgroundcheck') { set $seo_file inquire-backgroundcheck.html; }
+ if ($uri = '/inquire/homeservice') { set $seo_file inquire-homeservice.html; }
+ # ========== SEO 配置结束 ==========
+
+ proxy_set_header Host $host;
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+ proxy_set_header X-Forwarded-Host $server_name;
+ proxy_set_header X-Real-IP $remote_addr;
+ proxy_http_version 1.1;
+ proxy_set_header Upgrade $http_upgrade;
+ proxy_set_header Connection $http_connection;
+
+ access_log /www/sites/www.tianyuandb.com/log/access.log main;
+ error_log /www/sites/www.tianyuandb.com/log/error.log;
+
+ location ^~ /.well-known/acme-challenge {
+ allow all;
+ root /usr/share/nginx/html;
+ }
+
+ # SEO:爬虫访问时返回静态 HTML 模板
+ location /seo-templates/ {
+ internal;
+ add_header Content-Type "text/html; charset=utf-8";
+ add_header X-SEOMiddleware "nginx-prerendered";
+ }
+
+ location / {
+ if ($is_crawler = 1) {
+ rewrite ^ /seo-templates/$seo_file break;
+ }
+ try_files $uri $uri/ /index.html;
+ }
+
+ location /api/v1 {
+ proxy_pass http://127.0.0.1:21004;
+ proxy_set_header Host 127.0.0.1:$server_port;
+ proxy_set_header X-Real-IP $remote_addr;
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+ proxy_set_header REMOTE-HOST $remote_addr;
+ add_header X-Cache $upstream_cache_status;
+ proxy_set_header X-Host $host:$server_port;
+ proxy_set_header X-Scheme $scheme;
+ proxy_connect_timeout 30s;
+ proxy_read_timeout 86400s;
+ proxy_send_timeout 30s;
+ proxy_http_version 1.1;
+ proxy_set_header Upgrade $http_upgrade;
+ proxy_set_header Connection "upgrade";
+ }
+
+ location ^~ /api/v1/chat {
+ resolver 8.8.8.8 114.114.114.114 valid=10s;
+ resolver_timeout 5s;
+ set $backend "chat.guimiaokeji.com";
+ rewrite ^/api/v1/(.*)$ /$1 break;
+ proxy_pass https://$backend;
+ proxy_set_header Host $backend;
+ proxy_set_header X-Real-IP $remote_addr;
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+ proxy_set_header REMOTE-HOST $remote_addr;
+ proxy_set_header Upgrade $http_upgrade;
+ proxy_set_header Connection "upgrade";
+ proxy_set_header X-Forwarded-Proto $scheme;
+ proxy_http_version 1.1;
+ add_header X-Cache $upstream_cache_status;
+ add_header Cache-Control no-cache;
+ proxy_ssl_server_name off;
+ proxy_buffering off;
+ }
+
+ error_page 404 /404.html;
+ add_header Strict-Transport-Security "max-age=31536000";
+ include /www/sites/www.tianyuandb.com/redirect/*.conf;
+
+ if ($scheme = http) {
+ return 301 https://$host$request_uri;
+ }
+
+ ssl_certificate /www/sites/www.tianyuandb.com/ssl/fullchain.pem;
+ ssl_certificate_key /www/sites/www.tianyuandb.com/ssl/privkey.pem;
+ ssl_protocols TLSv1.3 TLSv1.2 TLSv1.1 TLSv1;
+ ssl_ciphers ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:!aNULL:!eNULL:!EXPORT:!DSS:!DES:!RC4:!3DES:!MD5:!PSK:!KRB5:!SRP:!CAMELLIA:!SEED;
+ ssl_prefer_server_ciphers on;
+ ssl_session_cache shared:SSL:10m;
+ ssl_session_timeout 10m;
+ error_page 497 https://$host$request_uri;
+ proxy_set_header X-Forwarded-Proto https;
+}
diff --git a/server/package.json b/server/package.json
new file mode 100644
index 0000000..dbb7c3e
--- /dev/null
+++ b/server/package.json
@@ -0,0 +1,27 @@
+{
+ "name": "tydata-seo-server",
+ "version": "1.0.0",
+ "description": "SPA SEO 优化 - 爬虫检测与静态 HTML 回退,与 useSEO.js 同步",
+ "main": "server-example-express.js",
+ "scripts": {
+ "start": "node server-example-express.js",
+ "dev": "node server-example-express.js",
+ "generate": "node generate-seo-templates.cjs",
+ "test": "node test-seo.js",
+ "test:crawler": "node test-crawler-detection.js"
+ },
+ "keywords": [
+ "seo",
+ "crawler",
+ "spa",
+ "prerender"
+ ],
+ "license": "MIT",
+ "dependencies": {
+ "express": "^4.18.2",
+ "compression": "^1.7.4"
+ },
+ "devDependencies": {
+ "nodemon": "^3.0.1"
+ }
+}
diff --git a/server/server-example-express.js b/server/server-example-express.js
new file mode 100644
index 0000000..811d63e
--- /dev/null
+++ b/server/server-example-express.js
@@ -0,0 +1,36 @@
+/**
+ * Express服务器示例
+ * 展示如何集成SEO中间件
+ */
+
+const express = require('express')
+const path = require('path')
+const SEOMiddleware = require('./middleware')
+
+const app = express()
+const port = process.env.PORT || 3000
+
+// 初始化SEO中间件
+const seoMiddleware = new SEOMiddleware({
+ templateDir: path.join(__dirname, '../public/seo-templates'),
+ debug: process.env.NODE_ENV === 'development'
+})
+
+// 应用SEO中间件(必须在静态文件服务之前)
+app.use(seoMiddleware.express())
+
+// 静态文件服务
+app.use(express.static(path.join(__dirname, '../dist')))
+
+// SPA路由处理
+app.get('*', (req, res) => {
+ res.sendFile(path.join(__dirname, '../dist/index.html'))
+})
+
+// 启动服务器
+app.listen(port, () => {
+ console.log(`🚀 服务器运行在 http://localhost:${port}`)
+ console.log(`🔍 SEO中间件已启用`)
+})
+
+module.exports = app
diff --git a/server/test-crawler-detection.js b/server/test-crawler-detection.js
new file mode 100644
index 0000000..d494d78
--- /dev/null
+++ b/server/test-crawler-detection.js
@@ -0,0 +1,112 @@
+/**
+ * 爬虫检测测试脚本
+ * 用于验证爬虫检测功能是否正常工作
+ */
+
+const CrawlerDetector = require('./crawler-detector')
+
+const detector = new CrawlerDetector()
+
+// 测试用例
+const testCases = [
+ // 爬虫User-Agent
+ { userAgent: 'Mozilla/5.0 (compatible; Baiduspider/2.0; +http://www.baidu.com/search/spider.html)', expected: true, description: '百度爬虫' },
+ { userAgent: 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)', expected: true, description: 'Google爬虫' },
+ { userAgent: 'Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)', expected: true, description: '必应爬虫' },
+ { userAgent: 'Sogou web spider/4.0(+http://www.sogou.com/docs/help/webmasters.htm#07)', expected: true, description: '搜狗爬虫' },
+ { userAgent: '360Spider', expected: true, description: '360爬虫' },
+ { userAgent: 'facebookexternalhit/1.1 (+http://www.facebook.com/externalhit_uatext.php)', expected: true, description: 'Facebook爬虫' },
+ { userAgent: 'Twitterbot/1.0', expected: true, description: 'Twitter爬虫' },
+ { userAgent: 'LinkedInBot/1.0 (compatible; Mozilla/5.0; +https://www.linkedin.com/help/linkedin/answer/8665)', expected: true, description: 'LinkedIn爬虫' },
+
+ // 正常浏览器User-Agent
+ { userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36', expected: false, description: 'Chrome浏览器' },
+ { userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:121.0) Gecko/20100101 Firefox/121.0', expected: false, description: 'Firefox浏览器' },
+ { userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.2 Safari/605.1.15', expected: false, description: 'Safari浏览器' },
+ { userAgent: 'Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Mobile/15E148 Safari/604.1', expected: false, description: 'iPhone Safari' },
+ { userAgent: 'Mozilla/5.0 (Linux; Android 13; SM-S908B) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Mobile Safari/537.36', expected: false, description: 'Android Chrome' },
+ { userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36 Edg/120.0.0.0', expected: false, description: 'Edge浏览器' },
+
+ // 边界情况
+ { userAgent: '', expected: false, description: '空User-Agent' },
+ { userAgent: 'Mozilla/5.0 (compatible; MyBot/1.0)', expected: true, description: '包含bot关键词' },
+ { userAgent: 'Mozilla/5.0 (compatible; Spider/1.0)', expected: true, description: '包含spider关键词' },
+ { userAgent: 'Mozilla/5.0 (compatible; Crawler/1.0)', expected: true, description: '包含crawler关键词' }
+]
+
+console.log('='.repeat(70))
+console.log('爬虫检测测试')
+console.log('='.repeat(70))
+console.log()
+
+let passed = 0
+let failed = 0
+
+testCases.forEach((testCase, index) => {
+ const req = {
+ headers: {
+ 'user-agent': testCase.userAgent
+ }
+ }
+
+ const result = detector.isCrawler(req)
+ const success = result === testCase.expected
+ const status = success ? '✓ 通过' : '✗ 失败'
+ const crawlerType = result ? detector.getCrawlerType(testCase.userAgent) : 'N/A'
+
+ if (success) {
+ passed++
+ console.log(`${status} 测试 ${index + 1}: ${testCase.description}`)
+ } else {
+ failed++
+ console.error(`${status} 测试 ${index + 1}: ${testCase.description}`)
+ console.error(` User-Agent: ${testCase.userAgent.substring(0, 80)}...`)
+ console.error(` 预期: ${testCase.expected}, 实际: ${result}`)
+ }
+
+ if (result) {
+ console.log(` 识别为: ${crawlerType} 爬虫`)
+ }
+})
+
+console.log()
+console.log('='.repeat(70))
+console.log(`测试结果: ${passed} 通过, ${failed} 失败, 共 ${testCases.length} 个测试`)
+console.log('='.repeat(70))
+console.log()
+
+// 测试爬虫类型识别
+console.log('爬虫类型识别测试:')
+console.log('-'.repeat(70))
+
+const crawlerTypes = [
+ { userAgent: 'Baiduspider', expected: 'baidu', description: '百度爬虫' },
+ { userAgent: 'Googlebot', expected: 'google', description: 'Google爬虫' },
+ { userAgent: 'bingbot', expected: 'bing', description: '必应爬虫' },
+ { userAgent: '360spider', expected: '360', description: '360爬虫' },
+ { userAgent: 'sogou spider', expected: 'sogou', description: '搜狗爬虫' },
+ { userAgent: 'facebookexternalhit', expected: 'facebook', description: 'Facebook爬虫' },
+ { userAgent: 'Twitterbot', expected: 'twitter', description: 'Twitter爬虫' },
+ { userAgent: 'linkedinbot', expected: 'linkedin', description: 'LinkedIn爬虫' }
+]
+
+let typePassed = 0
+crawlerTypes.forEach(test => {
+ const result = detector.getCrawlerType(test.userAgent)
+ const success = result === test.expected
+
+ if (success) {
+ typePassed++
+ console.log(`✓ ${test.description}: ${result}`)
+ } else {
+ console.error(`✗ ${test.description}: 预期 ${test.expected}, 实际 ${result}`)
+ }
+})
+
+console.log()
+console.log('='.repeat(70))
+console.log(`爬虫类型识别: ${typePassed}/${crawlerTypes.length} 正确`)
+console.log('='.repeat(70))
+
+// 退出码
+process.exit(failed === 0 ? 0 : 1)
diff --git a/server/test-seo.js b/server/test-seo.js
new file mode 100644
index 0000000..209c1d7
--- /dev/null
+++ b/server/test-seo.js
@@ -0,0 +1,178 @@
+/**
+ * SEO 端到端检测脚本
+ * 模拟爬虫与普通用户请求,验证是否返回正确的页面
+ *
+ * 使用前请先启动服务器: npm run start
+ * 然后运行: npm run test 或 node test-seo.js
+ */
+
+const http = require('http')
+const https = require('https')
+
+const BASE_URL = process.env.SEO_TEST_URL || 'http://localhost:3000'
+
+// 要检测的路由及期望的 SEO 标题关键词(与 useSEO.js 一致,天远数据)
+const ROUTES = [
+ { path: '/', titleKeyword: '天远数据' },
+ { path: '/agent', titleKeyword: '天远数据代理' },
+ { path: '/help', titleKeyword: '天远数据帮助中心' },
+ { path: '/inquire/personalData', titleKeyword: '个人综合风险报告' },
+ { path: '/agent/promote', titleKeyword: '推广码' },
+ { path: '/historyQuery', titleKeyword: '我的报告' }
+]
+
+function request(url, userAgent) {
+ return new Promise((resolve, reject) => {
+ const lib = url.startsWith('https') ? https : http
+ const req = lib.get(url, {
+ headers: { 'User-Agent': userAgent },
+ timeout: 10000
+ }, res => {
+ const chunks = []
+ res.on('data', chunk => chunks.push(chunk))
+ res.on('end', () => {
+ resolve({
+ statusCode: res.statusCode,
+ headers: res.headers,
+ body: Buffer.concat(chunks).toString('utf-8')
+ })
+ })
+ })
+ req.on('error', reject)
+ req.on('timeout', () => {
+ req.destroy()
+ reject(new Error('请求超时'))
+ })
+ })
+}
+
+function extractTitle(html) {
+ const match = html.match(/