hit count
August 4, 2024 · View on GitHub
简介
仓库访问频次计数徽章
效果:
如何部署自己的计数器?
使用腾讯云函数
使用腾讯云函数实现,后端采用redis计数
前提
- 有能够使云函数访问的Redis服务器,点我查看如何白嫖Redis服务器
- 腾讯云账号
或者你有服务器那直接部署在服务器上即可,不需要腾讯云函数。
步骤
-
克隆仓库到本地
git clone https://github.com/itning/hit-count.git -
进入目录中
cd ./hit-count/tencent-cloud-serverless-redis/src -
安装依赖
npm install -
修改redis的访问路径
修改
app.js文件const redisStore = new redis({ port: 16320, // Redis instance port, redis实例端口 host: "", // Redis instance host, redis实例host family: 4, // 4 (IPv4) or 6 (IPv6) password: "", // Redis instance password, redis实例密码 db: 0 }); -
添加访问域名白名单
修改
app.js文件const authorWhitelist = ["itning"];默认是作者自己,需要修改下
-
安装腾讯云SLS
npm install -g serverless -
上传
serverless deploy --debug -
进入腾讯云控制台查看结果
使用服务器
前提
- 有个服务器
- 有个公网IP
- 有个域名(可选)
步骤
-
克隆仓库到本地
git clone https://github.com/itning/hit-count.git -
进入目录
cd ./hit-count/server-redis -
安装依赖
npm install -
修改redis的访问路径
修改
app.js文件const redisStore = new redis({ port: 16320, // Redis instance port, redis实例端口 host: "", // Redis instance host, redis实例host family: 4, // 4 (IPv4) or 6 (IPv6) password: "", // Redis instance password, redis实例密码 db: 0 }); -
添加访问域名白名单
修改
app.js文件const authorWhitelist = ["itning"];默认是作者自己,需要修改下
-
启动
node app.js -
后台运行(可选)
# 安装pm2 npm install -g pm2 # 后台运行 pm2 app.js -o ./app.log -e error.log
使用CloudFlare Workers
-
克隆仓库到本地
git clone https://github.com/itning/hit-count.git -
进入目录中
cd ./hit-count/hit-count-cf-worker -
安装依赖
npm install -
部署
npm run deploy