Skip to content

Commit a62bc95

Browse files
authored
Merge pull request #23 from gujiangjiang/main
feat: 项目初始化为单 worker 应用架构 chore: 数据库由 Turso 迁移至 Cloudflare D1
2 parents 9105c27 + 0ee81a9 commit a62bc95

File tree

140 files changed

+5285
-10817
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

140 files changed

+5285
-10817
lines changed

.github/workflows/deploy.yml

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# 工作流名称
2+
name: Deploy to Cloudflare
3+
4+
# 触发条件
5+
on:
6+
push:
7+
branches:
8+
- main
9+
workflow_dispatch:
10+
11+
jobs:
12+
# 新增一个 job 用于检查密钥是否存在
13+
check_credentials:
14+
runs-on: ubuntu-latest
15+
name: Check for Cloudflare Credentials
16+
outputs:
17+
has_creds: ${{ steps.cf_creds.outputs.has_creds }}
18+
steps:
19+
- name: Check for Cloudflare credentials
20+
id: cf_creds
21+
run: |
22+
if [ -z "${{ secrets.CF_API_TOKEN }}" ] || [ -z "${{ secrets.CF_ACCOUNT_ID }}" ]; then
23+
echo "Cloudflare credentials not found, skipping deployment."
24+
echo "has_creds=false" >> $GITHUB_OUTPUT
25+
else
26+
echo "Cloudflare credentials found."
27+
echo "has_creds=true" >> $GITHUB_OUTPUT
28+
fi
29+
30+
# 部署 job,依赖于 check_credentials job 的结果
31+
deploy:
32+
runs-on: ubuntu-latest
33+
name: Deploy
34+
needs: check_credentials # 依赖于上一个 job
35+
if: needs.check_credentials.outputs.has_creds == 'true' # 只有在密钥存在时才运行
36+
steps:
37+
# 检出代码
38+
- name: Checkout
39+
uses: actions/checkout@v4
40+
41+
# 设置 pnpm (版本由根目录 package.json 的 "packageManager" 字段决定)
42+
- name: Setup pnpm
43+
uses: pnpm/action-setup@v4
44+
45+
# 设置 Node.js 环境
46+
- name: Setup Node.js
47+
uses: actions/setup-node@v4
48+
with:
49+
node-version-file: 'package.json'
50+
cache: 'pnpm'
51+
52+
# 安装依赖
53+
- name: Install dependencies
54+
# 修复:添加 --no-frozen-lockfile 标志
55+
# 这会告诉 pnpm 根据 package.json 的内容来安装依赖,即使 pnpm-lock.yaml 文件不是最新的。
56+
# 这样就解决了在部署环境中因锁文件不同步导致的安装失败问题。
57+
run: pnpm install --no-frozen-lockfile
58+
59+
# 运行构建
60+
- name: Build
61+
run: pnpm run build
62+
63+
# 配置 Wrangler (替换占位符)
64+
- name: Configure Wrangler
65+
run: |
66+
sed -i "s#\${D1_DATABASE_ID}#${D1_DATABASE_ID}#g" wrangler.toml
67+
sed -i "s#\${D1_DATABASE_NAME}#${D1_DATABASE_NAME}#g" wrangler.toml
68+
sed -i "s#\${EMAIL_DOMAIN}#${EMAIL_DOMAIN}#g" wrangler.toml
69+
sed -i "s#\${COOKIES_SECRET}#${COOKIES_SECRET}#g" wrangler.toml
70+
sed -i "s#\${TURNSTILE_KEY}#${TURNSTILE_KEY}#g" wrangler.toml
71+
sed -i "s#\${TURNSTILE_SECRET}#${TURNSTILE_SECRET}#g" wrangler.toml
72+
env:
73+
D1_DATABASE_ID: ${{ secrets.D1_DATABASE_ID }}
74+
D1_DATABASE_NAME: ${{ secrets.D1_DATABASE_NAME }}
75+
EMAIL_DOMAIN: ${{ secrets.EMAIL_DOMAIN }}
76+
COOKIES_SECRET: ${{ secrets.COOKIES_SECRET }}
77+
TURNSTILE_KEY: ${{ secrets.TURNSTILE_KEY }}
78+
TURNSTILE_SECRET: ${{ secrets.TURNSTILE_SECRET }}
79+
80+
# 新增:在部署前应用 D1 数据库迁移
81+
# 这一步会明确地告诉 Wrangler 远程执行 D1 数据库的迁移脚本。
82+
- name: Apply D1 Migrations
83+
run: npx wrangler d1 migrations apply ${{ secrets.D1_DATABASE_NAME }} --remote
84+
env:
85+
CLOUDFLARE_API_TOKEN: ${{ secrets.CF_API_TOKEN }}
86+
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CF_ACCOUNT_ID }}
87+
88+
# 部署到 Cloudflare Workers
89+
- name: Deploy
90+
uses: cloudflare/wrangler-action@v3
91+
with:
92+
apiToken: ${{ secrets.CF_API_TOKEN }}
93+
accountId: ${{ secrets.CF_ACCOUNT_ID }}

README.md

Lines changed: 48 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
<div align="center">
22
<h1>𝐕𝐌𝐀𝐈𝐋.𝐃𝐄𝐕</h1>
33
<p><a href="https://discord.gg/d68kWCBDEs">Discord</a> · <a href="https://github.com/oiov/vmail/blob/main/README_en.md">English</a> | 简体中文</p>
4-
<p>使用 Cloudflare email worker 实现的临时电子邮件服务</p>
4+
<p>使用 Cloudflare Email Worker 实现的临时电子邮件服务</p>
55
<a href="https://trendshift.io/repositories/8681" target="_blank"><img src="https://trendshift.io/api/badge/repositories/8681" alt="yesmore%2Fvmail | Trendshift" style="width: 250px; height: 55px;" width="250" height="55"/></a>
6-
<!-- <img src="https://img.inke.app/file/beb0212f96c6cd37eaeb8.jpg"/> -->
76
</div>
87

98
[WR.DO](https://wr.do) 临时邮箱已上线,与 Vmail 同款原理,使用 CF 转发邮件,并支持发件,支持多域名。仓库:[oiov/wr.do](https://github.com/oiov/wr.do),体验地址: [wr.do/emails](https://wr.do/emails)
@@ -14,57 +13,74 @@
1413
- ✈️ 支持邮件收发
1514
- ✨ 支持保存密码,找回邮箱
1615
- 😄 支持多域名后缀
17-
- 🚀 快速部署,无需服务器
16+
- 🚀 快速部署,纯 Cloudflare 方案,无需服务器
1817

1918
原理:
2019

2120
- Email worker 接收电子邮件
22-
- 前端显示电子邮件(remix)
23-
- 邮件存储(sqlite)
24-
- 发信使用 MailChannel API
21+
- 前端 (Vite + React) 显示电子邮件
22+
- 邮件存储 (Cloudflare D1)
23+
- 发信使用 MailChannels API
2524

2625
## 👋 自部署教程
2726

27+
本项目已完全基于 Cloudflare Pages 和 Cloudflare D1 构建,大大简化了部署流程。您只需要一个托管在 Cloudflare 上的域名即可。
28+
2829
### 准备工作
2930

3031
- [Cloudflare](https://dash.cloudflare.com/) 账户与托管在 Cloudflare 上的域名
31-
- [turso](https://turso.tech) sqlite 数据库(个人免费计划足够)
32-
- [Vercel](https://vercel.com)[fly.io](https://fly.io) 账号部署前端用户界面
33-
- 本地安装 [Nodejs](https://nodejs.org) 环境 (版本 >= 18.x)
32+
- 本地安装 [Node.js](https://nodejs.org) 环境 (版本 >= 18.x) 和 [pnpm](https://pnpm.io/installation)
3433

35-
### 接收邮件教程
34+
### 自动部署 (推荐)
3635

37-
查看 [receive-tutorial.md](/docs/receive-tutorial.md)
36+
本项目已包含一个预先配置好的 GitHub Action 工作流,可以帮助您自动将 vMail 应用部署到 Cloudflare。
3837

39-
### 发送邮件教程
38+
详细步骤请参考 [GitHub Action 自动部署教程](/docs/github-action-tutorial.md)
4039

41-
```JSON
42-
注意:不再建议使用此方法,原因参考 issue#17,vmail.dev 将下线发件功能
43-
```
40+
### 手动部署步骤
4441

45-
查看 [send-tutorial.md](/docs/send-tutorial.md)
42+
1. **克隆项目到本地**
43+
```bash
44+
git clone https://github.com/oiov/vmail
45+
cd vmail
46+
pnpm install
47+
```
4648

47-
## 🔨 本地运行调试
49+
2. **创建 Cloudflare D1 数据库**
50+
在 Cloudflare 控制台或使用 Wrangler CLI 创建一个 D1 数据库。
4851

49-
```bash
50-
git clone https://github.com/oiov/vmail
51-
cd vmail
52-
# 安装依赖
53-
pnpm install
52+
3. **配置 `wrangler.toml`**
53+
将根目录下的 `wrangler.toml` 文件中的 `${...}` 占位符替换为您的 Cloudflare 和 D1 配置信息。您也可以通过 Cloudflare Pages 的环境变量来设置这些值。
5454

55-
# 运行端口 localhost:3000
56-
pnpm run remix:dev
57-
```
55+
4. **构建和部署**
56+
```bash
57+
# 构建前端应用
58+
pnpm run build
59+
60+
# 部署到 Cloudflare
61+
pnpm run deploy
62+
```
63+
Wrangler 将会自动处理前端静态资源和 Worker 的部署,并根据配置应用数据库迁移。
5864

59-
运行前复制 `apps/remix/.env.example` 文件并重命名为 `apps/remix/.env`,填写必要的环境变量。
65+
5. **配置电子邮件路由**
66+
在您的 Cloudflare 域名管理界面,进入 `Email` -> `Email Routing` -> `Routes`,设置一个 `Catch-all` 规则,将所有发送到您域名的邮件 `Send to a Worker`,选择您刚刚部署的 Worker。
6067

61-
## Deploy with Edgeone
68+
## 🔨 本地运行调试
6269

63-
[![使用 EdgeOne Pages 部署](https://cdnstatic.tencentcs.com/edgeone/pages/deploy.svg)](https://edgeone.ai/pages/new?repository-url=https%3A%2F%2Fgithub.com%2Foiov%2Fvmail)
70+
1. **复制环境变量文件**
71+
```bash
72+
# 此命令会创建一个本地环境变量文件,wrangler dev 会自动加载
73+
cp .env.example .env
74+
```
6475

65-
## 🌈 下一步计划
76+
2. **填写本地环境变量**
77+
`.env` 文件中填写必要的环境变量,特别是 `D1_DATABASE_ID` 等。您需要先在 Cloudflare 创建一个 D1 数据库用于本地开发。
6678

67-
- [ ] 使用 [Cloudflare D1](https://developers.cloudflare.com/d1/) 数据库重构,简化部署流程
79+
3. **启动开发服务器**
80+
```bash
81+
pnpm run dev
82+
```
83+
该命令会同时启动前端 Vite 开发服务器和本地的 Wrangler Worker 环境。
6884

6985
## ❤️ 交流群
7086

@@ -78,7 +94,7 @@ pnpm run remix:dev
7894
Please check out these previous works that helped inspire the creation of vmail. 🙏
7995

8096
- [akazwz/smail](https://github.com/akazwz/smail)
81-
- [email.ml](email.ml)
97+
- [email.ml](https://email.ml)
8298

8399
## 📝 License
84100

@@ -89,4 +105,4 @@ GNU General Public License v3.0
89105
[![Star History Chart](https://api.star-history.com/svg?repos=oiov/vmail&type=Date)](https://star-history.com/#oiov/vmail&Date)
90106

91107

92-
[![Powered by DartNode](https://dartnode.com/branding/DN-Open-Source-sm.png)](https://dartnode.com "Powered by DartNode - Free VPS for Open Source")
108+
[![Powered by DartNode](https://dartnode.com/branding/DN-Open-Source-sm.png)](https://dartnode.com "Powered by DartNode - Free VPS for Open Source")

README_en.md

Lines changed: 54 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,58 +2,88 @@
22
<h1>𝐕𝐌𝐀𝐈𝐋.𝐃𝐄𝐕</h1>
33
<p><a href="https://discord.gg/d68kWCBDEs">Discord</a> · English | <a href="/README.md">简体中文</a></p>
44
<p>Temporary email service build with email worker.</p>
5-
<!-- <img src="https://img.inke.app/file/beb0212f96c6cd37eaeb8.jpg"/> -->
6-
</div>
5+
</div>
76

87
## Features
98

109
- 🎯 Privacy-friendly, no registration required, out-of-the-box
1110
- ✈️ Support email sending and receiving
1211
- ✨ Support saving passwords and retrieving email addresses
1312
- 😄 Support multiple domain name suffixes
14-
- 🚀 100% open source, quick deployment, no server required
13+
- 🚀 100% open source, quick deployment, pure Cloudflare solution, no server required
1514

16-
Principles:
15+
Principles:
1716

18-
- Receiving emails (email worker)
19-
- Display email (remix)
20-
- Mail Storage (sqlite)
21-
- [Nodejs](https://nodejs.org) >= 18
17+
- Receiving emails (Cloudflare Email Worker)
18+
- Display email (Vite + React on Cloudflare Pages)
19+
- Mail Storage (Cloudflare D1)
20+
- [Node.js](https://nodejs.org) >= 18
2221

23-
> Worker receives email -> saves to database -> client queries email
22+
> Worker receives email -> saves to D1 database -> client queries email
2423
2524
## Self-hosted Tutorial
2625

26+
This project is now fully based on Cloudflare Pages and Cloudflare D1, which greatly simplifies the deployment process. All you need is a domain name hosted on Cloudflare.
27+
2728
### Requirements
2829

2930
- [Cloudflare](https://dash.cloudflare.com/) account and a domain name hosted on Cloudflare
30-
- [turso](https://turso.tech) sqlite (a free plan available for personal use)
31-
- [Vercel](https://vercel.com) or [fly.io](https://fly.io) to deploy Remix app
31+
- Local installation of [Node.js](https://nodejs.org) (version >= 18.x) and [pnpm](https://pnpm.io/installation)
32+
33+
### Automatic Deployment (Recommended)
34+
35+
This project includes a pre-configured GitHub Action workflow to help you automatically deploy the vMail application to Cloudflare.
36+
37+
For detailed steps, please refer to the [GitHub Action Auto-Deployment Tutorial](/docs/github-action-tutorial.md).
3238

33-
### Receiving Emails steps
39+
### Manual Deployment Steps
3440

35-
See [receive-tutorial-en.md](/docs//receive-tutorial-en.md)
41+
1. **Clone the project locally**
42+
```bash
43+
git clone https://github.com/oiov/vmail
44+
cd vmail
45+
pnpm install
46+
```
3647

37-
### Sending Emails steps
48+
2. **Create a Cloudflare D1 Database**
49+
Create a D1 database in the Cloudflare dashboard or using the Wrangler CLI.
3850

39-
See [send-tutorial-en.md](/docs/send-tutorial-en.md)
51+
3. **Configure `wrangler.toml`**
52+
Replace the `${...}` placeholders in the `wrangler.toml` file in the root directory with your Cloudflare and D1 configuration information. You can also set these values through environment variables in Cloudflare Pages.
53+
54+
4. **Build and Deploy**
55+
```bash
56+
# Build the frontend application
57+
pnpm run build
58+
59+
# Deploy to Cloudflare
60+
pnpm run deploy
61+
```
62+
Wrangler will automatically handle the deployment of frontend static assets and the Worker, and apply database migrations according to the configuration.
63+
64+
5. **Configure Email Routing Rules**
65+
In your Cloudflare domain management interface, go to `Email` -> `Email Routing` -> `Routes`, set up a `Catch-all` rule, and set the action to `Send to a Worker`, selecting the Worker you just deployed.
4066

4167
## Local development
4268

43-
copy `apps/remix/.env.example` to `apps/remix/.env` and fill in the necessary environment variables.
69+
1. **Copy the environment variable file**
70+
```bash
71+
# This command creates a local environment variable file that wrangler dev will load automatically
72+
cp .env.example .env
73+
```
74+
75+
2. **Fill in local environment variables**
76+
Fill in the necessary environment variables in the `.env` file, especially `D1_DATABASE_ID`, etc. You need to create a D1 database in Cloudflare for local development first.
4477

45-
```bash
46-
git clone https://github.com/oiov/vmail
47-
cd vmail
48-
pnpm install
78+
3. **Start the development server**
79+
```bash
80+
pnpm run dev
81+
```
82+
This command starts both the frontend Vite development server and the local Wrangler Worker environment at the same time.
4983

50-
# run on localhost:3000
51-
pnpm run remix:dev
52-
```
5384

5485
## Community Group
5586

56-
- 加微信 `yesmore_cc` 拉讨论群 (**备注你的职业**)
5787
- Discord: https://discord.gg/d68kWCBDEs
5888

5989
## License

apps/email-api/.gitignore

Lines changed: 0 additions & 10 deletions
This file was deleted.

apps/email-api/README.md

Lines changed: 0 additions & 8 deletions
This file was deleted.

apps/email-api/package.json

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)