Skip to content

itning/hit-count

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

hit count

GitHub stars GitHub forks GitHub watchers GitHub followers

GitHub issues GitHub license GitHub last commit GitHub repo size in bytes language

简介

仓库访问频次计数徽章

效果: hitCount

如何部署自己的计数器?

使用腾讯云函数

使用腾讯云函数实现,后端采用redis计数

前提

  1. 有能够使云函数访问的Redis服务器,点我查看如何白嫖Redis服务器
  2. 腾讯云账号

或者你有服务器那直接部署在服务器上即可,不需要腾讯云函数。

步骤

  1. 克隆仓库到本地

    git clone https://github.com/itning/hit-count.git

  2. 进入目录中

    cd ./hit-count/tencent-cloud-serverless-redis/src

  3. 安装依赖

    npm install

  4. 修改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
    });
  5. 添加访问域名白名单

    修改app.js文件

    const authorWhitelist = ["itning"];

    默认是作者自己,需要修改下

  6. 安装腾讯云SLS

    npm install -g serverless

  7. 上传

    serverless deploy --debug

  8. 进入腾讯云控制台查看结果

使用服务器

前提

  1. 有个服务器
  2. 有个公网IP
  3. 有个域名(可选)

步骤

  1. 克隆仓库到本地

    git clone https://github.com/itning/hit-count.git

  2. 进入目录

    cd ./hit-count/server-redis

  3. 安装依赖

    npm install

  4. 修改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
    });
  5. 添加访问域名白名单

    修改app.js文件

    const authorWhitelist = ["itning"];

    默认是作者自己,需要修改下

  6. 启动

    node app.js

  7. 后台运行(可选)

    # 安装pm2
    npm install -g pm2
    # 后台运行
    pm2 app.js -o ./app.log -e error.log