@@ -8,4 +8,130 @@ It saves in memory all "`submission.created`" events and surfaces the submission
88
99Clicking on each submission URL opens up the SimplePDF viewer for this specific submission
1010
11- A live demo can be seen here: https://webhooks.simplepdf.co
11+ A live demo can be seen here: https://webhooks.simplepdf.com
12+
13+
14+ ---
15+
16+
17+ ## Deployment Guide
18+
19+ _ This guide explains how to deploy the SimplePDF webhooks example to Cloudflare Workers (Free Plan compatible)._
20+
21+ ### Prerequisites
22+
23+ - Node.js installed
24+ - Cloudflare account (free plan works)
25+ - Wrangler CLI installed
26+
27+ ### Setup Steps
28+
29+ #### 1. Install Dependencies
30+
31+ ``` bash
32+ npm install
33+ ```
34+
35+ #### 2. Login to Cloudflare
36+
37+ ``` bash
38+ npx wrangler login
39+ ```
40+
41+ This will open a browser window to authenticate with your Cloudflare account.
42+
43+ #### 3. Create KV Namespace
44+
45+ Create a KV namespace to store webhook events:
46+
47+ ``` bash
48+ npx wrangler kv:namespace create " SIMPLEPDF_WEBHOOKS_KV"
49+ ```
50+
51+ This will output something like:
52+ ```
53+ Created namespace with id "abc123def456"
54+ ```
55+
56+ Copy the namespace ID and update ` wrangler.toml ` :
57+
58+ ``` toml
59+ [[kv_namespaces ]]
60+ binding = " SIMPLEPDF_WEBHOOKS_KV"
61+ id = " YOUR_KV_NAMESPACE_ID" # Replace with your actual ID
62+ ```
63+
64+ #### 4. Configure Environment Variables (Optional)
65+
66+ Edit ` wrangler.toml ` to customize the company identifier:
67+
68+ ``` toml
69+ [vars ]
70+ COMPANY_IDENTIFIER = " your-company-name"
71+ ```
72+
73+ #### 5. Deploy to Cloudflare
74+
75+ ``` bash
76+ npm run deploy
77+ ```
78+
79+ Your worker will be deployed and you'll receive a URL like:
80+ ```
81+ https://simplepdf-webhooks.YOUR_SUBDOMAIN.workers.dev
82+ ```
83+
84+ ### Testing Locally
85+
86+ Run the worker locally for testing:
87+
88+ ``` bash
89+ npm run dev
90+ ```
91+
92+ This will start a local development server at ` http://localhost:8787 `
93+
94+ ### Configuration
95+
96+ #### Cron Schedule
97+
98+ The worker automatically cleans up submissions older than 15 minutes. The cron schedule is configured in ` wrangler.toml ` :
99+
100+ ``` toml
101+ [triggers ]
102+ crons = [" */15 * * * *" ] # Runs every 15 minutes
103+ ```
104+
105+ #### Environment Variables
106+
107+ Available environment variables in ` wrangler.toml ` :
108+
109+ - ` COMPANY_IDENTIFIER ` : Your SimplePDF company identifier (default: "webhooks-playground")
110+
111+ ### Differences from Express Version
112+
113+ The Cloudflare Workers version has these key differences:
114+
115+ 1 . ** Storage** : Uses Cloudflare KV instead of in-memory arrays
116+ 2 . ** Cleanup** : Uses Cron Triggers instead of setInterval
117+ 3 . ** Runtime** : Uses Service Worker API instead of Express
118+ 4 . ** Stateless** : Each request is independent, no shared state
119+
120+ ### Architecture
121+
122+ #### Request Handling
123+
124+ - ` GET / ` - Lists all submissions
125+ - ` GET /submissions/:id ` - View specific submission details
126+ - ` POST /webhooks ` - Receive webhook events from SimplePDF
127+ - ` GET /flush ` - Clear all submissions
128+
129+ #### Storage Schema
130+
131+ Events are stored in KV with keys: ` submission:{submissionId} `
132+
133+ Each value is a JSON string containing the full webhook event payload.
134+
135+ #### Scheduled Cleanup
136+
137+ A cron trigger runs every 15 minutes to delete submissions older than 15 minutes.
0 commit comments