Bare Bear

Upvoteworkers

Cloudflare Workers Upvote Backend Setup

1. Create Cloudflare Account

  1. Go to https://dash.cloudflare.com/sign-up
  2. Sign up with email and verify
  3. Skip any domain setup prompts

2. Create KV Namespaces

  1. In Cloudflare dashboard, click Workers & Pages in left sidebar
  2. Click KV tab
  3. Click Create namespace
  4. Name it upvote-count → Click Add
  5. Click Create namespace again
  6. Name it upvote-record → Click Add

You should now see both namespaces listed.

3. Create Worker

  1. Go back to Workers & Pages
  2. Click Create button → Create Worker
  3. Name it upvote-api (or whatever you want)
  4. Click Deploy
  5. Click Edit code

4. Add Worker Code

  1. Delete all the default code in the editor
  2. Copy the worker code from: ==[LINK TO GITHUB SCRIPT]==
  3. Paste it into the editor
  4. Click Deploy (top right)

5. Generate Salt Secret

Open your terminal and run:

openssl rand -base64 32

Copy the output (a long random string like xK9mP2vL8nQ4tR6wY1zA5bC3dE7fG0hI2jK4lM6nO8pQ=)

You could also use an online tool like this one, but it’s probably not a good idea.

6. Configure Environment Variables

  1. In your worker, click SettingsVariables
  2. Click Add variable

Variable 1: SALT_SECRET

Variable 2: ALLOWED_ORIGINS

7. Bind KV Namespaces

Still in SettingsVariables, scroll to KV Namespace Bindings:

Binding 1:

Binding 2:

8. Set your upvote API URL in Blot

  1. Go to SettingsTriggers
  2. Under Routes, you’ll see a *.workers.dev URL
  3. Copy this URL (e.g., https://upvote-api.your-account.workers.dev)
  4. Set upvote_url in package.json to this URL, whether via the blot.im frontend or your sync service.

9. Testing

Browser Test (from your allowed domain):

Open browser console on your website and run:

fetch('https://upvote-api.your-account.workers.dev/count?post=test-123')
  .then(r => r.json())
  .then(console.log);

Should return: {code: 0, msg: "success", data: {post: "test-123", count: 0, hasUpvoted: false}}

Test upvote:

fetch('https://upvote-api.your-account.workers.dev/upvote', {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: JSON.stringify({postId: 'test-123', diff: 1})
}).then(r => r.json()).then(console.log);

Should return: {code: 0, msg: "success", data: {count: 1}}

Test again:

fetch('https://upvote-api.your-account.workers.dev/count?post=test-123')
  .then(r => r.json())
  .then(console.log);

Should return: {code: 0, msg: "success", data: {post: "test-123", count: 1, hasUpvoted: true}}

Common Issues

“SALT_SECRET is not defined” - Go back to Settings → Variables and make sure you added it as a Secret (not Text) - Check spelling is exactly SALT_SECRET

“CORS error” on my own site - Check ALLOWED_ORIGINS exactly matches your domain - Must include https:// - No trailing slash: https://example.com NOT https://example.com/ - Check www vs non-www (add both if needed)

“UPVOTE_COUNT is not defined” - Go to Settings → Variables → KV Namespace Bindings - Make sure variable names are exactly UPVOTE_COUNT and UPVOTE_RECORD - Make sure they’re bound to the correct namespaces

Worker returns 404 - Make sure you deployed the code (clicked Deploy button) - Try the worker URL directly in browser - should return JSON

Free Tier Limits (November 2025)

For a personal blog, you’ll probably never hit these limits.

Last Modified  •  #plugin 

Reply via email