Giter Site home page Giter Site logo

willin / cloudflare-pageviews-worker Goto Github PK

View Code? Open in Web Editor NEW
3.0 2.0 5.0 74 KB

A Simple Pageviews API using Cloudflare Worker

Home Page: https://blog.csdn.net/jslygwx/article/details/122224575

License: Apache License 2.0

TypeScript 80.16% JavaScript 19.84%

cloudflare-pageviews-worker's Introduction

cloudflare-pageviews-worker

GitHub followers GitHub forks

English

使用说明

第一步,Fork 本项目,并 Clone 至本地。

第二步,配置环境

# 安装命令行
npm install -g @cloudflare/wrangler
# 登录 Cloudflare
wrangler login
# 创建 KV 存储桶
wrangler kv:namespace create "views" --env production

打开 wrangler.toml,修改以下配置:

  • account_id
  • zone_id
  • route
  • kv_namespaces 中的 id

通过 Github Actions 自动部署,或者手动执行 wrangler publish --env production

需要在仓库设置中,配置 Secrets。名称为: CF_API_TOKEN,传入 Cloudflare 的 API Token。

API Token 生成访问: https://dash.cloudflare.com/profile/api-tokens ,选择使用模板 Edit Cloudflare Workers 创建即可。

配置成功后需要给 DNS 中添加一条 A 解析,设置为: 192.0.2.1 并通过 CDN 加速。

API

PUT /pv?slug=optional

QueryString 参数:

  • slug: string 可选

如果不传,或传入 total,则返回为总计点击量。

{
  "result": {
    "slug": "total",
    "pv": 10
  }
}

P.S. 其中,GET 请求也可以访问,但仅当 PUT 请求时,会额外将访问计数累加。

GET /list?slugs=optional,optional

QueryString 参数:

  • slugs: string 可选,请将 string[] 用 , 分隔

如果不传,则返回为总计点击量。

{
  "result": [
    {
      "slug": "total",
      "pv": 10
    },
    // ...
  ]
}

LICENSE

Apache License 2.0

cloudflare-pageviews-worker's People

Contributors

willin avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.