Skip to content

Commit 19a78d3

Browse files
fixes
1 parent 7e780a4 commit 19a78d3

5 files changed

Lines changed: 58 additions & 22 deletions

File tree

version 2/.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
TEMP_MAIL_DB_ID=c82663ac-62b6-4ba6-be81-cbe297f2a3dd
33

44
# Mail Configuration
5-
MAIL_DOMAIN=temp.example.com
5+
MAIL_DOMAIN=gxtend.vip
66
RESEND_API_KEY=your_resend_api_key_here
77

88
# Security

version 2/DEPLOY.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,3 +199,39 @@ To receive emails, you must configure Cloudflare Email Routing.
199199
- **Database errors**: Ensure you ran the `d1 execute` command (Step 4.2).
200200
- **"Uncaught (in promise)"**: Check your `wrangler secret list` to ensure all secrets are set.
201201
- **Email not received**: Verify your domain's MX records in Cloudflare DNS settings match what Email Routing requires.
202+
203+
---
204+
205+
## Local Development
206+
207+
You can run the application locally in two modes: **Local Mode** (using a local temporary database) or **Remote Mode** (connecting to your live Cloudflare D1 database).
208+
209+
### Option 1: Local Backend (Default)
210+
*Use this for safe development without affecting production data.*
211+
212+
1. **Start Frontend**:
213+
```bash
214+
npm run dev
215+
```
216+
(Runs on `http://localhost:5173`)
217+
218+
2. **Start Backend** (in a new terminal):
219+
```bash
220+
npm run dev:backend
221+
```
222+
(Runs on `http://localhost:8787` using a local SQLite file)
223+
224+
### Option 2: Remote Backend (Live Data)
225+
*Use this to debug with your actual production database.*
226+
227+
1. **Start Frontend**:
228+
```bash
229+
npm run dev
230+
```
231+
232+
2. **Start Backend** (in a new terminal):
233+
```bash
234+
npm run dev:backend:remote
235+
```
236+
(Runs on `http://localhost:8787` but connects to your generic Cloudflare D1 DB)
237+

version 2/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
"build": "tsc -b && vite build",
99
"lint": "eslint .",
1010
"preview": "vite preview",
11-
"deploy:setup": "node scripts/setup.js"
11+
"deploy:setup": "node scripts/setup.js",
12+
"dev:backend": "wrangler dev",
13+
"dev:backend:remote": "wrangler dev --remote"
1214
},
1315
"dependencies": {
1416
"@radix-ui/react-checkbox": "^1.3.3",
@@ -46,4 +48,4 @@
4648
"typescript-eslint": "^8.46.4",
4749
"vite": "^7.2.4"
4850
}
49-
}
51+
}

version 2/src/pages/mailbox/index.tsx

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { useState, useEffect, useCallback, useMemo } from 'react';
2+
import { useSearchParams } from 'react-router-dom';
23
import { useAuth } from '@/context/AuthContext';
34
import { apiFetch } from '@/lib/api';
45
import { Button } from '@/components/ui/button';
@@ -29,11 +30,12 @@ interface EmailDetail extends EmailSummary {
2930
}
3031

3132
export default function Mailbox() {
32-
useAuth(); // We just need the hook to run, or we can remove it if we don't use the return.
33-
// Actually the original code accessed user.mailboxAddress, but now we don't.
34-
// But usually we keep it to ensure context is valid or for redirection if protected route.
35-
// The lint says '_' is assigned but never used.
36-
// Let's just call useAuth() without destructuring if we don't use the user object.
33+
const { user } = useAuth();
34+
const [searchParams] = useSearchParams();
35+
const queryMailbox = searchParams.get('mailbox');
36+
37+
const targetMailbox = queryMailbox || user?.mailboxAddress;
38+
3739
const [emails, setEmails] = useState<EmailSummary[]>([]);
3840
const [selectedEmail, setSelectedEmail] = useState<EmailDetail | null>(null);
3941
const [isLoadingList, setIsLoadingList] = useState(false);
@@ -45,20 +47,13 @@ export default function Mailbox() {
4547
const [isChangePasswordOpen, setIsChangePasswordOpen] = useState(false);
4648

4749
const fetchEmails = useCallback(async (silent = false) => {
50+
if (!targetMailbox) return;
51+
4852
if (!silent) setIsLoadingList(true);
4953
try {
5054
// Fetch more emails to better support client-side search
51-
await apiFetch<unknown>(`/api/emails?limit=100&offset=0`); // Keeping 'any' for now or defining type if possible, but 'any' is easiest if structure varies.
52-
// Wait, I should try to fix 'any' if possible.
53-
// The lint complained about apiFetch<any>.
54-
// Let's use 'unknown' or a better type.
55-
// But apiFetch<T> returns T.
56-
// Let's define the expected response.
57-
/*
58-
The worker returns either an array (if standard) or { results: ... } (if D1).
59-
We handle both.
60-
*/
61-
const response = await apiFetch<{ results?: EmailSummary[] } | EmailSummary[]>(`/api/emails?limit=100&offset=0`);
55+
const endpoint = `/api/emails?mailbox=${encodeURIComponent(targetMailbox)}&limit=100&offset=0`;
56+
const response = await apiFetch<{ results?: EmailSummary[] } | EmailSummary[]>(endpoint);
6257

6358
if (Array.isArray(response)) {
6459
setEmails(response);
@@ -71,11 +66,13 @@ export default function Mailbox() {
7166
} finally {
7267
if (!silent) setIsLoadingList(false);
7368
}
74-
}, []);
69+
}, [targetMailbox]);
7570

7671
useEffect(() => {
77-
fetchEmails();
78-
}, [fetchEmails]);
72+
if (targetMailbox) {
73+
fetchEmails();
74+
}
75+
}, [fetchEmails, targetMailbox]);
7976

8077
// Auto-refresh logic
8178
useEffect(() => {

version 2/wrangler.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ database_id = "46d67b6b-4a93-43ab-9769-61906e7aec39" # Updated with user's datab
1111
# Environment Variables
1212
[vars]
1313
# FORWARD_RULES="[{\"prefix\":\"vip\",\"email\":\"a@example.com\"},{\"prefix\":\"*\",\"email\":\"admin@example.com\"}]"
14+
MAIL_DOMAIN = "gxtend.vip"
1415

1516
# Static Assets (Vite build output)
1617
[assets]

0 commit comments

Comments
 (0)