First step, fork this repo and clone to your local directory.
Sencond, configure environment.
# Install command line tools
npm install -g @cloudflare/wrangler
# Login Cloudflare
wrangler login
# Create KV Namespace
wrangler kv:namespace create "views" --env production
Open and edit wrangler.toml
:
- account_id
- zone_id
- route
- id in kv_namespaces
You may use Github Actions to deploy automatically or manually execute wrangler publish --env production
.
Add Secrets in your Github repo settings, and name it CF_API_TOKEN
, value should pass in Cloudflare API Token.
You can generate an API token from: https://dash.cloudflare.com/profile/api-tokens ,select Edit Cloudflare Workers
to create.
Then add a DNS record, A: 192.0.2.1
, Proxied.
Query:
slug
: string, optional
if null, will return total.
Results like:
{
"result": {
"slug": "total",
"pv": 10
}
}
P.S. Use PUT
method (GET method will not add count).
Query:
slugs
: string, optional, join string[] with,
if null, will return total.
Result like:
{
"result": [
{
"slug": "total",
"pv": 10
},
// ...
]
}
Apache License 2.0