Open Kounter 是一个基于 EdgeOne Pages Functions 和 KV 存储的无服务器计数器服务,旨在替代 LeanCloud 为静态网站(如 Hexo)提供 PV/UV 统计功能。它包含一个完整的管理后台,支持数据管理、导入导出、域名白名单和 Passkey 无密码登录。
你可以通过 EdgeOne Pages 一键部署或手动配置构建:
一键部署:
注意:点击上方按钮前,建议先 Fork 本仓库,并在跳转后的页面中确认仓库地址为你 Fork 后的地址。
手动部署配置:
edgeone.json)npm run builddist22更多 EdgeOne Pages文档:https://pages.edgeone.ai/zh/document/product-introduction
本项目依赖 KV 存储来保存计数数据和配置信息,请务必配置:
创建 KV 命名空间
绑定 KV 到项目
OPEN_KOUNTER重新部署项目
部署并配置完成后,访问你的项目网址,首次访问将引导你设置管理员 Token。
. ├── client/ │ └── adapter.js # 客户端适配器,模拟 LeanCloud 行为 ├── edge-functions/ # 后端逻辑 (EdgeOne Functions) │ └── api/ │ ├── auth.js # 认证逻辑 │ ├── counter.js # 核心计数器逻辑 │ ├── init.js # 初始化接口 │ └── passkey.js # Passkey 相关逻辑 ├── src/ # 前端管理后台 (Vue 3 + Vite) │ ├── components/ │ │ ├── dashboard/ │ │ │ ├── CounterList.vue # 计数器列表 │ │ │ ├── DataBackup.vue # 数据备份与恢复 │ │ │ ├── DomainConfig.vue # 域名白名单配置 │ │ │ ├── PasskeyManager.vue # Passkey 管理 │ │ │ ├── SingleCounterManager.vue # 单个计数器管理 │ │ │ └── TotalStats.vue # 统计概览 │ │ ├── Dashboard.vue # 仪表盘主组件 │ │ └── Login.vue # 登录组件 │ ├── utils/ # 工具函数 │ ├── App.vue # 主应用组件 │ ├── main.js # 入口文件 │ └── style.css # 全局样式 ├── edgeone.json # EdgeOne 配置文件 ├── index.html # HTML 入口 ├── package.json # 项目依赖 ├── tailwind.config.js # Tailwind 配置 └── vite.config.js # Vite 配置
所有 API 的基础路径为 /api。
GET /api/countertarget (必填,计数器的 Key,如 site-pv){
"code": 0,
"data": {
"time": 100,
"target": "site-pv",
"created_at": 1700000000000,
"updated_at": 1700000000000
}
}
POST /api/counter{
"action": "inc",
"target": "site-pv"
}
POST /api/counter{
"action": "batch_inc",
"requests": [
{ "target": "site-pv" },
{ "target": "/posts/hello-world/" }
]
}
需要在 Header 中携带 Authorization: Bearer <YOUR_TOKEN>。
POST /api/counter{
"action": "set",
"target": "site-pv",
"value": 1000
}
POST /api/counter{
"action": "delete",
"target": "site-pv"
}
POST /api/counter{
"action": "list",
"page": 1,
"pageSize": 20
}
POST /api/counter{ "action": "export_all" }POST /api/counter{
"action": "import_all",
"data": { ... } // 导出的 JSON 数据
}
POST /api/counter{
"action": "set_config",
"allowedDomains": ["example.com", "*.example.com"]
}
本项目基于 MIT License 开源。