Skip to content

Commit 7919b0d

Browse files
authored
chore: use cf workers (#1069)
1 parent 23d7fa5 commit 7919b0d

File tree

6 files changed

+17
-18
lines changed

6 files changed

+17
-18
lines changed

.github/workflows/cloudflare-preview.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
- name: Build for Cloudflare Workers
4040
run: pnpm web build:h5-netlify
4141
env:
42-
CF_PAGES: 1
42+
CF_WORKERS: 1
4343

4444
- name: Deploy to Cloudflare Workers
4545
id: deploy

.github/workflows/deploy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ jobs:
9292
- name: Build for Cloudflare Workers
9393
run: pnpm web build:h5-netlify
9494
env:
95-
CF_PAGES: 1
95+
CF_WORKERS: 1
9696

9797
- name: Deploy to Cloudflare Workers
9898
uses: cloudflare/wrangler-action@v3

apps/web/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
"build:analyze": "cross-env ANALYZE=true vite build",
1818
"compile:extension": "pnpm --prefix ./src/extension run compile",
1919
"preview": "pnpm run build && vite preview",
20-
"wrangler:dev": "cross-env CF_PAGES=1 vite --host",
21-
"wrangler:deploy": "cross-env CF_PAGES=1 pnpm run build:h5-netlify && wrangler deploy",
20+
"wrangler:dev": "cross-env CF_WORKERS=1 vite --host",
21+
"wrangler:deploy": "cross-env CF_WORKERS=1 pnpm run build:h5-netlify && wrangler deploy",
2222
"release:cli": "node ./scripts/release.js",
2323
"ext:dev": "wxt",
2424
"ext:zip": "wxt zip",

apps/web/src/components/editor/UploadImgDialog.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,15 +159,15 @@ function telegramSubmit(values: any) {
159159
// 当前是否为网页(http/https 协议)
160160
const isWebsite = window.location.protocol.startsWith(`http`)
161161
162-
// Cloudflare Pages 环境
163-
const isCfPage = import.meta.env.CF_PAGES === `1`
162+
// Cloudflare Workers 环境
163+
const isCfWorkers = import.meta.env.CF_WORKERS === `1`
164164
165165
// 插件模式运行(如 chrome-extension://)
166166
const isPluginMode = !isWebsite
167167
168168
// 是否需要填写 proxyOrigin(只在 非插件 且 非CF页面 时需要)
169169
const isProxyRequired = computed(() => {
170-
return !isPluginMode && !isCfPage
170+
return !isPluginMode && !isCfWorkers
171171
})
172172
173173
const mpPlaceholder = computed(() => {

apps/web/src/utils/file.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -333,14 +333,15 @@ async function getMpToken(appID: string, appsecret: string, proxyOrigin: string)
333333
}
334334
return ``
335335
}
336-
// Cloudflare Pages 环境
337-
const isCfPage = import.meta.env.CF_PAGES === `1`
336+
// Cloudflare Workers 环境
337+
const isCfWorkers = import.meta.env.CF_WORKERS === `1`
338+
338339
async function mpFileUpload(file: File) {
339340
let { appID, appsecret, proxyOrigin } = JSON.parse(
340341
localStorage.getItem(`mpConfig`)!,
341342
)
342-
// 未填写代理域名且是cfpages环境
343-
if (!proxyOrigin && isCfPage) {
343+
// 未填写代理域名且是 Cloudflare Workers 环境时,使用当前域名作为代理域名
344+
if (!proxyOrigin && isCfWorkers) {
344345
proxyOrigin = window.location.origin
345346
}
346347
const access_token = await getMpToken(appID, appsecret, proxyOrigin)

apps/web/vite.config.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,12 @@ import { VitePWA } from 'vite-plugin-pwa'
1313
import { VitePluginRadar } from 'vite-plugin-radar'
1414
import vueDevTools from 'vite-plugin-vue-devtools'
1515

16+
const isNetlify = process.env.SERVER_ENV === `NETLIFY`
1617
const isUTools = process.env.SERVER_ENV === `UTOOLS`
17-
const isCfWorkers = process.env.CF_PAGES === `1`
18-
const base
19-
= process.env.SERVER_ENV === `NETLIFY` || isCfWorkers
20-
? `/`
21-
: isUTools
22-
? `./`
23-
: `/md/`
18+
const isCfWorkers = process.env.CF_WORKERS === `1`
19+
const isCfPages = process.env.CF_PAGES === `1`
20+
21+
const base = isNetlify || isCfWorkers || isCfPages ? `/` : isUTools ? `./` : `/md/`
2422

2523
export default defineConfig(({ mode }) => {
2624
const env = loadEnv(mode, process.cwd())

0 commit comments

Comments
 (0)