File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ # Cloudflare Pages 部署指南
2+
3+ 本项目原生支持部署到 Cloudflare Pages,并支持通过环境变量动态修改配置(替代 Docker 的 ` start.sh ` )。
4+
5+ ## 部署步骤
6+
7+ 1 . ** Fork 本项目** 到你的 GitHub 账号。
8+ 2 . 登录 [ Cloudflare Dashboard] ( https://dash.cloudflare.com/ ) ,进入 ** Pages** 页面。
9+ 3 . 点击 ** Create a project** -> ** Connect to Git** 。
10+ 4 . 选择你 Fork 的 ` subweb ` 仓库。
11+ 5 . 在 ** Build settings** 中:
12+ * ** Framework preset** : 选择 ` Vue.js `
13+ * ** Build command** : ` npm run build `
14+ * ** Build output directory** : ` dist `
15+ 6 . 点击 ** Save and Deploy** 。
16+
17+ ## 环境变量配置
18+
19+ 在 Cloudflare Pages 项目的 ** Settings** -> ** Environment variables** 中,你可以添加以下变量来覆盖默认配置(与 Docker 环境变量保持一致):
20+
21+ | 变量名 | 描述 | 默认值 |
22+ | :--- | :--- | :--- |
23+ | ` SITE_NAME ` | 网站标题 | ` Subconverter Web ` |
24+ | ` API_URL ` | 本地后端 API 地址 | ` http://127.0.0.1:25500 ` |
25+ | ` SHORT_URL ` | 短链接服务地址 | ` https://s.ops.ci ` |
26+
27+ 配置完成后,请触发一次 ** Retry deployment** 以生效。
28+
29+ ## 原理说明
30+
31+ 项目包含 ` functions/conf/config.js.js ` 文件。这是一个 Cloudflare Pages Function,它会拦截对 ` /conf/config.js ` 的请求,并根据环境变量动态生成 JavaScript 配置代码返回给浏览器。
Original file line number Diff line number Diff line change 1+ export async function onRequest ( context ) {
2+ const { env } = context ;
3+
4+ // Default values mirroring the original config.js
5+ const siteName = env . SITE_NAME || 'Subconverter Web' ;
6+ const shortUrl = env . SHORT_URL || 'https://s.ops.ci' ;
7+ const apiUrl = env . API_URL || 'http://127.0.0.1:25500' ;
8+
9+ const config = {
10+ siteName : siteName ,
11+ apiBackends : [
12+ {
13+ name : '本地服务' ,
14+ url : apiUrl ,
15+ } ,
16+ {
17+ name : '官方服务' ,
18+ url : 'https://sub.xeton.dev' ,
19+ } ,
20+ ] ,
21+ shortUrl : shortUrl ,
22+ menuItem : [
23+ {
24+ title : '首页' ,
25+ link : '/' ,
26+ target : '' ,
27+ } ,
28+ {
29+ title : 'GitHub' ,
30+ link : 'https://github.com/Aethersailor/subweb' ,
31+ target : '_blank' ,
32+ } ,
33+ ] ,
34+ remoteConfigOptions : [
35+ {
36+ value : 'https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/config/ACL4SSR_Online.ini' ,
37+ text : 'ACL4SSR Online' ,
38+ } ,
39+ {
40+ value : 'https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/config/ACL4SSR_Online_Full.ini' ,
41+ text : 'ACL4SSR Online Full' ,
42+ } ,
43+ ] ,
44+ } ;
45+
46+ const jsContent = `window.config = ${ JSON . stringify ( config , null , 2 ) } ;` ;
47+
48+ return new Response ( jsContent , {
49+ headers : {
50+ 'content-type' : 'application/javascript;charset=UTF-8' ,
51+ } ,
52+ } ) ;
53+ }
You can’t perform that action at this time.
0 commit comments