https://github.com/willin/cloudflare-pageviews-worker
A Simple Pageviews API using Cloudflare Worker
https://github.com/willin/cloudflare-pageviews-worker
Last synced: about 1 year ago
JSON representation
A Simple Pageviews API using Cloudflare Worker
- Host: GitHub
- URL: https://github.com/willin/cloudflare-pageviews-worker
- Owner: willin
- License: apache-2.0
- Created: 2021-12-29T03:56:49.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2021-12-29T12:53:46.000Z (over 4 years ago)
- Last Synced: 2025-04-10T17:41:36.343Z (about 1 year ago)
- Language: TypeScript
- Homepage: https://blog.csdn.net/jslygwx/article/details/122224575
- Size: 72.3 KB
- Stars: 2
- Watchers: 2
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.en.md
- License: LICENSE
Awesome Lists containing this project
README
# cloudflare-pageviews-worker
[](https://github.com/willin) 
[简体中文](./README.md)
## Usage
First step, fork this repo and clone to your local directory.
Sencond, configure environment.
```bash
# 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: ,select `Edit Cloudflare Workers` to create.
Then add a DNS record, A: `192.0.2.1`, Proxied.

## API
### PUT /pv?slug=optional
Query:
- `slug`: string, optional
if null, will return total.
Results like:
```js
{
"result": {
"slug": "total",
"pv": 10
}
}
```
P.S. Use `PUT` method (GET method will not add count).
### GET /list?slugs=optional,optional
Query:
- `slugs`: string, optional, join string[] with `,`
if null, will return total.
Result like:
```js
{
"result": [
{
"slug": "total",
"pv": 10
},
// ...
]
}
```
## LICENSE
Apache License 2.0