Skip to content

ihsangan/workers-d1-blog

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Cloudflare Workers D1 Blog

Getting started

Click the deploy button and follow the instructions

Deploy to Cloudflare Workers

  • Setting up wrangler.toml file for D1 binding and other site informations.

copy SQL command bellow

CREATE TABLE IF NOT EXISTS blog_posts (
    title TEXT NOT NULL,
    url TEXT PRIMARY KEY NOT NULL UNIQUE,
    time INTEGER,
    content TEXT
);

Open Cloudflare dashboard , select (or create) database, go to console section and execute command, Check whether the table has been created in the tables section.

Copy db name and ID and adjust to wrangler.toml

  • setup login info for create and editing articles

Go to repository setting > secrets and variables > actions

Create repository secrets with name USERNAME & PASSWORD

Usage

Endpoints

  • Home (/)

    • Displays the list of blog posts.
  • Create New Post (/new)

    • Displays the form to create a new blog post. Requires basic authentication.
  • Create Post (/create)

    • Handles form submission to create a new post. Requires basic authentication.
  • Read Post (/post/:article)

    • Displays a specific blog post.
  • Edit Post (/edit/:article)

    • Displays the form to edit a blog post. Handles form submission to update or delete the post. Requires basic authentication.

Troubleshooting

chrome_screenshot_7 Jul 2024 17 19 30

If you get error like this just simply Re-run job