Skip to content

Commit 77b738b

Browse files
committed
update readmes
1 parent be95ece commit 77b738b

File tree

3 files changed

+110
-17
lines changed

3 files changed

+110
-17
lines changed

README.md

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,21 @@ This monorepo contains:
1818
- **Environment variables** for secure key management
1919
- **Comprehensive tests** using Vitest
2020

21-
### Frontend (`packages/frontend-vanilla/`)
21+
### Frontend - Vanilla JavaScript (`packages/frontend-vanilla/`)
2222
- **Vanilla JavaScript** demo application
2323
- **jQuery integration** for AJAX calls
2424
- **Environment detection** (localhost vs production)
2525
- **Live Disqus integration** with login/logout functionality
2626
- **Responsive design** that works on mobile and desktop
2727

28+
### Frontend - React (`packages/frontend-react/`)
29+
- **React 18** with modern hooks and functional components
30+
- **Vite** for fast development and optimized builds
31+
- **Axios** for HTTP requests to the SSO backend
32+
- **disqus-react** package for seamless Disqus integration
33+
- **ESLint** configuration for code quality
34+
- **Modern ES6+** syntax and module system
35+
2836
## 🛠️ Key Features
2937

3038
- **🔐 Secure Authentication**: HMAC-SHA1 signed payloads for Disqus SSO
@@ -48,11 +56,19 @@ sso-demo/
4856
│ │ │ └── sso.test.js # Test suite
4957
│ │ ├── wrangler.toml # Cloudflare Workers config
5058
│ │ └── package.json
51-
│ └── frontend-vanilla/ # Vanilla JS frontend
52-
│ ├── index.html # Main demo page
59+
│ ├── frontend-vanilla/ # Vanilla JS frontend
60+
│ │ ├── index.html # Vanilla JS demo page
61+
│ │ └── package.json
62+
│ └── frontend-react/ # React frontend
5363
│ ├── src/
54-
│ │ └── disqus-sso.js # SSO client library
64+
│ │ ├── App.jsx # Main React component
65+
│ │ ├── components/
66+
│ │ │ └── DisqusSSO.jsx # SSO integration component
67+
│ │ └── main.jsx # React entry point
68+
│ ├── vite.config.js # Vite configuration
69+
│ ├── eslint.config.js # ESLint configuration
5570
│ └── package.json
71+
├── index.html # Landing page for demos
5672
├── .github/
5773
│ └── workflows/
5874
│ ├── deploy.yml # Backend deployment
@@ -89,13 +105,17 @@ nano packages/backend/.dev.vars
89105
# Start backend (Cloudflare Workers)
90106
yarn dev
91107

92-
# In another terminal, serve frontend
108+
# In another terminal, serve vanilla frontend
93109
yarn dev:vanilla
110+
111+
# Or serve React frontend
112+
yarn dev:react
94113
```
95114

96115
### 4. Test Locally
97116
- Backend API: `http://localhost:8787`
98-
- Frontend Demo: `http://localhost:3000` (or open `packages/frontend-vanilla/index.html`)
117+
- Vanilla Frontend: `http://localhost:3000` (or open `packages/frontend-vanilla/index.html`)
118+
- React Frontend: `http://localhost:3001`
99119

100120
## 📡 API Endpoints
101121

@@ -147,10 +167,15 @@ ALLOWED_ORIGINS=https://yourdomain.com,http://localhost:3000
147167
```
148168

149169
### Frontend Configuration
150-
The frontend automatically detects the environment:
170+
Both frontends automatically detect the environment:
151171
- **Development**: Uses `http://localhost:8787`
152172
- **Production**: Uses `https://sso-serverless.ctang-402.workers.dev`
153173

174+
**React-specific configuration:**
175+
- Vite build configuration in `vite.config.js`
176+
- Base path set to `/sso-demo/react/` for GitHub Pages deployment
177+
- ESLint rules for React development
178+
154179
## 🚢 Deployment
155180

156181
### Backend (Cloudflare Workers)
@@ -167,7 +192,10 @@ Automatically deployed via GitHub Actions when you push to `main`:
167192
```
168193

169194
### Frontend (GitHub Pages)
170-
Automatically deployed when frontend files change:
195+
Automatically deployed when frontend files change. Both vanilla and React frontends are deployed to:
196+
- **Landing page**: `https://disqus.github.io/sso-demo/`
197+
- **Vanilla demo**: `https://disqus.github.io/sso-demo/vanilla/`
198+
- **React demo**: `https://disqus.github.io/sso-demo/react/`
171199

172200
1. Enable GitHub Pages in repository settings:
173201
- Go to Settings → Pages
@@ -191,6 +219,19 @@ yarn workspace @disqus-sso/backend test
191219
yarn workspace @disqus-sso/backend test --watch
192220
```
193221

222+
## 🏗️ Building
223+
224+
```bash
225+
# Build React frontend for production
226+
yarn build:react
227+
228+
# Build both frontends for GitHub Pages
229+
yarn build:pages
230+
231+
# Build all workspaces
232+
yarn build
233+
```
234+
194235
## 🔒 Security
195236

196237
- **HMAC-SHA1 Signatures**: All SSO payloads are cryptographically signed

packages/backend/README.md

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,37 @@ yarn dev
4141

4242
Your serverless function will be available at `http://localhost:8787`
4343

44+
**Production URL:** `https://sso-serverless.ctang-402.workers.dev/`
45+
4446
### 4. Test the API
4547

46-
**Health Check:**
48+
**Health Check (Local):**
4749
```bash
4850
curl http://localhost:8787/health
4951
```
5052

51-
**Generate SSO Token:**
53+
**Health Check (Production):**
54+
```bash
55+
curl https://sso-serverless.ctang-402.workers.dev/health
56+
```
57+
58+
**Generate SSO Token (Local):**
5259
```bash
53-
curl -X POST http://localhost:8787/sso \\
54-
-H "Content-Type: application/json" \\
60+
curl -X POST http://localhost:8787/sso \
61+
-H "Content-Type: application/json" \
62+
-d '{
63+
"user": {
64+
"username": "john_doe",
65+
"id": "12345",
66+
"email": "[email protected]"
67+
}
68+
}'
69+
```
70+
71+
**Generate SSO Token (Production):**
72+
```bash
73+
curl -X POST https://sso-serverless.ctang-402.workers.dev/sso \
74+
-H "Content-Type: application/json" \
5575
-d '{
5676
"user": {
5777
"username": "john_doe",
@@ -113,6 +133,8 @@ yarn test
113133

114134
## Deployment
115135

136+
The backend is deployed to: **`https://sso-serverless.ctang-402.workers.dev/`**
137+
116138
### 1. Install Wrangler CLI
117139

118140
```bash

packages/frontend-react/README.md

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ A React implementation of the Disqus SSO demo using Vite as the build tool.
55
## Features
66

77
- **React Components**: Modern React with hooks for state management
8+
- **Official Disqus Integration**: Uses the official `disqus-react` package for seamless Disqus embedding
89
- **Environment Detection**: Automatically uses localhost for development and production URL for deployment
9-
- **Fetch API**: Uses modern fetch API instead of jQuery
10+
- **Axios HTTP Client**: Modern HTTP client for API requests instead of jQuery
1011
- **Responsive Design**: Works well on desktop and mobile devices
1112
- **Real-time SSO Testing**: Login/logout functionality with live Disqus integration
1213
- **Better Error Handling**: Comprehensive error states and loading indicators
@@ -39,12 +40,29 @@ The build output will be in the `dist/` directory.
3940

4041
## How It Works
4142

42-
1. **Login Button**: Calls your backend API with test user data using fetch API
43+
1. **Login Button**: Calls your backend API with test user data using Axios
4344
2. **Environment Detection**: Uses localhost in development, production URL when deployed
44-
3. **SSO Integration**: Passes the SSO payload to Disqus for authentication
45-
4. **Logout Button**: Clears the current user and resets Disqus
45+
3. **SSO Integration**: Passes the SSO payload to Disqus for authentication via the `DiscussionEmbed` component
46+
4. **Logout Button**: Clears the current user and resets Disqus using the `window.DISQUS.reset()` API
4647
5. **State Management**: Uses React hooks for managing loading states and debug information
4748

49+
## Disqus Integration
50+
51+
This implementation uses the **official `disqus-react` package** which provides:
52+
53+
- **`DiscussionEmbed` Component**: Renders the Disqus comment thread with proper React lifecycle management
54+
- **Automatic Script Loading**: Handles loading and cleanup of Disqus scripts
55+
- **SSO Configuration**: Supports Disqus SSO configuration through component props
56+
- **React-Friendly**: Properly integrates with React's virtual DOM and component lifecycle
57+
58+
### Key Advantages of `disqus-react`:
59+
60+
-**Official Support**: Maintained by Disqus team
61+
-**React Optimized**: Designed specifically for React applications
62+
-**Better Performance**: Handles script loading and cleanup automatically
63+
-**Type Safety**: Includes TypeScript definitions
64+
-**SSO Ready**: Built-in support for Single Sign-On configuration
65+
4866
## API Integration
4967

5068
The frontend communicates with your Cloudflare Workers backend:
@@ -55,10 +73,20 @@ The frontend communicates with your Cloudflare Workers backend:
5573
## Component Structure
5674

5775
- `App.jsx`: Main application component
58-
- `components/DisqusSSO.jsx`: Main SSO component with login/logout functionality
76+
- `components/DisqusSSO.jsx`: Main SSO component with login/logout functionality and `DiscussionEmbed` integration
5977
- `index.css`: Styling that matches the vanilla JS version
6078
- `main.jsx`: React application entry point
6179

80+
### DisqusSSO Component Details
81+
82+
The main component (`DisqusSSO.jsx`) demonstrates:
83+
84+
- **State Management**: Uses `useState` for login status and debug information
85+
- **SSO Integration**: Configures the `DiscussionEmbed` component with SSO settings
86+
- **API Calls**: Makes POST requests to the backend using Axios
87+
- **Disqus Reset**: Uses `window.DISQUS.reset()` for logout functionality
88+
- **Error Handling**: Graceful error states and user feedback
89+
6290
## Deployment
6391

6492
This can be deployed to GitHub Pages alongside the vanilla JS version by:
@@ -72,7 +100,9 @@ The React version would be available at: `https://[username].github.io/sso-serve
72100
## Development Notes
73101

74102
- Uses modern React patterns with functional components and hooks
103+
- Leverages the **official `disqus-react` package** for better integration than manual script loading
75104
- Implements proper cleanup in useEffect to prevent memory leaks
76105
- Handles loading states and errors gracefully
77106
- Maintains the same visual styling as the vanilla JS version
78107
- Uses Vite for fast development and optimized production builds
108+
- Axios replaces jQuery for cleaner, Promise-based HTTP requests

0 commit comments

Comments
 (0)