Skip to content
Open

11 #13

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
931fb2a
fix(cloudflare): enforce edge runtime + disable eslint indent
dappweb Jan 26, 2026
8766218
fix(eslint): use Link component, add trailing comma, fix array spacing
dappweb Jan 26, 2026
632fdef
fix(build): increase Node.js heap memory to 4GB
dappweb Jan 26, 2026
340a405
fix(lint): add 2 empty lines after import in not-found.tsx
dappweb Jan 27, 2026
f8c5542
fix(build): disable source maps and increase memory to 8GB
dappweb Jan 27, 2026
d1aa850
chore(cloudflare): 集成 Cloudflare 部署功能
zhuyinjun Jan 28, 2026
77efb01
chore(deps): 锁定 Solana 相关依赖版本并更新云平台依赖
zhuyinjun Jan 28, 2026
3e8cfcb
提交新的lock
zhuyinjun Jan 28, 2026
b6f750e
修改output
zhuyinjun Jan 28, 2026
c6909a9
更新lock
zhuyinjun Jan 28, 2026
ca092e7
修改cf 函数
zhuyinjun Jan 28, 2026
d90f96a
修改cf worker 内存
zhuyinjun Jan 28, 2026
361407d
修改编译错误
zhuyinjun Jan 28, 2026
0a4db8c
减少内存
zhuyinjun Jan 28, 2026
fabd2e5
fix: remove edge runtime from pages
zhuyinjun Jan 28, 2026
e4b410e
增加中英文适配
zhuyinjun Jan 30, 2026
eea7f66
修改错误
zhuyinjun Jan 30, 2026
a449af7
修改符号错误
zhuyinjun Jan 30, 2026
e13b6cd
chore(config): 添加 .gitattributes 配置文件
zhuyinjun Jan 30, 2026
38c0df8
style(locale): 格式化代码以符合团队样式指南
zhuyinjun Jan 30, 2026
5eb427b
style(locale): 调整一下样式
zhuyinjun Jan 30, 2026
cfb8f28
Update wrangler config name to azuro-example-app
cloudflare-workers-and-pages[bot] Jan 30, 2026
a6b17a8
Merge pull request #1 from dappweb/update_worker_name_to_azuro-exampl…
dappweb Feb 1, 2026
90837cd
修改
zhuyinjun Feb 2, 2026
abadaa9
Merge remote-tracking branch 'origin/main'
zhuyinjun Feb 2, 2026
1166ac9
修改环境变量
zhuyinjun Feb 2, 2026
1ef84cc
测试
zhuyinjun Feb 2, 2026
6f6ba2c
修改url
zhuyinjun Feb 2, 2026
8477395
拦截请求避免跨域
zhuyinjun Feb 2, 2026
8afb2ff
修改拦截规则
zhuyinjun Feb 2, 2026
bb1c054
feat: 实现 GraphQL 代理解决 Cloudflare Worker CORS 问题
zhuyinjun Feb 2, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .env
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
NEXT_PUBLIC_AFFILIATE_ADDRESS=0xaa86b91a7c2366dd2a7000c7ebf69223e1fa8f8a
NEXT_PUBLIC_AFFILIATE_ADDRESS=0x78Fe3dB12c7A337A5551e6e600ddD8D30459e2Ba
NEXT_PUBLIC_WALLETCONNECT_ID=c4deaddf39937c2243196f5d0f6ca8d7 # get your own project ID - https://cloud.walletconnect.com/sign-in
NEXT_PUBLIC_BASE_URL=https://azuro-example.org
NEXT_PUBLIC_BASE_URL=https://azuro-example-app.dappweb.workers.dev
NEXT_PUBLIC_COMPANY_NAME="Flat.bet"
NEXT_PUBLIC_PRIVY_APP_ID=cm1p6gkel04f362oq6bxn2nal

AZURO_UNSTABLE_DEV_ENABLED=true
AZURO_UNSTABLE_DEV_ENABLED=false
8 changes: 1 addition & 7 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -333,12 +333,6 @@
"@typescript-eslint/no-misused-promises": "warn",
"@typescript-eslint/consistent-type-imports": "error",
"@typescript-eslint/type-annotation-spacing": "error",
"@typescript-eslint/indent": [
"error",
2,
{
"SwitchCase": 1
}
]
"@typescript-eslint/indent": "off"
}
}
35 changes: 35 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# 默认:自动识别文本文件并统一为 LF
* text=auto eol=lf

# 明确指定为文本并归一化
*.ts text
*.tsx text
*.js text
*.jsx text
*.mjs text
*.cjs text
*.json text
*.md text
*.yml text
*.yaml text
*.html text
*.css text
*.scss text
*.sh text
*.config.js text
*.config.mjs text
*.config.ts text

# 二进制文件不参与换行符转换
*.png binary
*.jpg binary
*.jpeg binary
*.gif binary
*.ico binary
*.woff binary
*.woff2 binary
*.ttf binary
*.eot binary

# SVG 按文本处理(便于 diff),若需按二进制可改为 binary
*.svg text
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,7 @@ yarn-error.log*
# typescript
*.tsbuildinfo
next-env.d.ts

# cloudflare
.open-next/
.wrangler/
149 changes: 149 additions & 0 deletions DEPLOYMENT-GUIDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
# GraphQL 代理部署指南

## ✅ 实现完成

已成功实现 Azuro SDK 的 GraphQL 请求代理,解决 Cloudflare Worker 环境中的 CORS 跨域问题。

## 📁 关键文件

1. **`worker-wrapper.js`** - Cloudflare Worker 自定义包装器
- 拦截 `/api/graphql-proxy` 请求
- 在 Worker 层面转发到第三方 GraphQL 端点
- 绕过 CORS 限制

2. **`src/helpers/fetchPolyfill.ts`** - 客户端 fetch 拦截器
- 拦截所有包含 `thegraph`、`onchainfeed.org`、`azuro` 的请求
- 重定向到 `/api/graphql-proxy`

3. **`src/compositions/Providers/Providers.tsx`** - Polyfill 初始化
- 在模块加载时立即初始化 polyfill

4. **`wrangler.jsonc`** - Cloudflare Worker 配置
- 使用 `worker-wrapper.js` 作为入口点

## 🚀 部署步骤

### 1. 构建项目
```bash
npm run cf:build
```

### 2. 本地预览(可选)
```bash
npm run cf:preview
```

### 3. 部署到 Cloudflare
```bash
npm run cf:deploy
```

## 🔍 验证部署

部署后,打开浏览器开发者工具:

1. 打开 Network 标签
2. 访问你的应用
3. 查找 `/api/graphql-proxy` 请求
4. 确认请求成功返回数据(状态码 200)

## 📊 工作原理

```
客户端 (浏览器)
fetch('https://thegraph-1.onchainfeed.org/...')
Fetch Polyfill 拦截
重定向到 /api/graphql-proxy
Cloudflare Worker (worker-wrapper.js)
在服务端 fetch 真实 URL (无 CORS 限制)
第三方 GraphQL 端点
返回数据
Cloudflare Worker
转发响应
客户端 SDK
接收数据,继续处理
```

## 🎯 优势

- ✅ **SDK 完全兼容** - 所有 Azuro SDK hooks 正常工作
- ✅ **类型安全** - 保留所有 TypeScript 类型
- ✅ **最小修改** - 只添加了代理层,不修改 SDK
- ✅ **透明转发** - SDK 不知道请求被代理了
- ✅ **性能优化** - 在 Worker 层面处理,速度快

## 🐛 故障排查

### 如果看到 530 错误:

1. 检查 Cloudflare Worker 日志
2. 确认 `worker-wrapper.js` 正确部署
3. 验证 `wrangler.jsonc` 配置正确

### 如果请求仍然直连第三方:

1. 检查浏览器控制台是否有 polyfill 初始化日志
2. 确认 `[Fetch Polyfill] ✅ Initialized` 消息出现
3. 清除浏览器缓存并刷新

### 查看 Worker 日志:

```bash
wrangler tail
```

或在 Cloudflare Dashboard:
- Workers & Pages → 你的 Worker → Logs

## 📝 配置代理域名

如需代理其他域名,编辑 `src/helpers/fetchPolyfill.ts`:

```typescript
const PROXY_DOMAINS = [
'thegraph',
'onchainfeed.org',
'azuro',
// 添加其他域名
'your-domain.com',
]
```

然后重新构建和部署。

## 🔄 更新流程

当需要更新代码时:

```bash
# 1. 修改代码
# 2. 重新构建
npm run cf:build

# 3. 部署
npm run cf:deploy
```

## ⚠️ 注意事项

1. **Windows 兼容性** - OpenNext 在 Windows 上可能有问题,建议使用 WSL
2. **构建时间** - 首次构建可能需要较长时间
3. **环境变量** - 确保 `.env` 文件配置正确

## 📞 支持

如遇到问题,请检查:
1. Cloudflare Worker 日志
2. 浏览器控制台日志
3. Network 请求详情
Loading