-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit a9b5d18
Showing
41 changed files
with
13,625 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
name: 部署布灵图床前端到Cloudflare Pages | ||
|
||
on: | ||
push: | ||
branches: [main] | ||
pull_request: | ||
branches: [main] | ||
workflow_dispatch: | ||
|
||
jobs: | ||
deploy: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
deployments: write | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: 1.Setup Node | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: '20' | ||
|
||
- name: 2.Install Dependencies | ||
run: | | ||
echo "开始安装依赖..." | ||
npm install &>/dev/null || { | ||
echo "❌ 依赖安装失败" | ||
exit 1 | ||
} | ||
npm install -g wrangler &>/dev/null || { | ||
echo "❌ wrangler 安装失败" | ||
exit 1 | ||
} | ||
which wrangler # 显示 wrangler 的安装位置 | ||
wrangler --version # 显示 wrangler 版本 | ||
echo "✅ 依赖安装成功" | ||
- name: 3.Create Cloudflare Pages Project | ||
env: | ||
CLOUDFLARE_API_TOKEN: ${{ secrets.CF_API_TOKEN }} | ||
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CF_ACCOUNT_ID }} | ||
run: | | ||
echo "检查并创建 Pages 项目..." | ||
curl -X POST "https://api.cloudflare.com/client/v4/accounts/${{ secrets.CF_ACCOUNT_ID }}/pages/projects" \ | ||
-H "Authorization: Bearer ${{ secrets.CF_API_TOKEN }}" \ | ||
-H "Content-Type: application/json" \ | ||
--data '{ | ||
"name": "buling-imgbed-frontend", | ||
"production_branch": "main" | ||
}' > /dev/null 2>&1 || true | ||
echo "✅ Pages 项目检查完成" | ||
- name: 4.Deploy to Cloudflare Pages | ||
env: | ||
CLOUDFLARE_API_TOKEN: ${{ secrets.CF_API_TOKEN }} | ||
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CF_ACCOUNT_ID }} | ||
NUXT_PUBLIC_API_BASE: ${{ secrets.NUXT_PUBLIC_API_BASE }} | ||
run: | | ||
echo "开始部署到 Cloudflare Pages..." | ||
npm run pages:deploy &>/dev/null || { | ||
echo "❌ 部署失败" | ||
exit 1 | ||
} | ||
echo "✅ 部署成功" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
node_modules | ||
*.log* | ||
.nuxt | ||
.nitro | ||
.cache | ||
.output | ||
.env | ||
dist | ||
# Node dependencies | ||
node_modules | ||
|
||
# Logs | ||
logs | ||
*.log | ||
|
||
# Misc | ||
.DS_Store | ||
.fleet | ||
.idea | ||
|
||
# Local env files | ||
.env | ||
.env.* | ||
!.env.example | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
const urls = new Set(); | ||
|
||
function checkURL(request, init) { | ||
const url = | ||
request instanceof URL | ||
? request | ||
: new URL( | ||
(typeof request === "string" | ||
? new Request(request, init) | ||
: request | ||
).url | ||
); | ||
if (url.port && url.port !== "443" && url.protocol === "https:") { | ||
if (!urls.has(url.toString())) { | ||
urls.add(url.toString()); | ||
console.warn( | ||
`WARNING: known issue with \`fetch()\` requests to custom HTTPS ports in published Workers:\n` + | ||
` - ${url.toString()} - the custom port will be ignored when the Worker is published using the \`wrangler deploy\` command.\n` | ||
); | ||
} | ||
} | ||
} | ||
|
||
globalThis.fetch = new Proxy(globalThis.fetch, { | ||
apply(target, thisArg, argArray) { | ||
const [request, init] = argArray; | ||
checkURL(request, init); | ||
return Reflect.apply(target, thisArg, argArray); | ||
}, | ||
}); |
11 changes: 11 additions & 0 deletions
11
.wrangler/tmp/bundle-9AtjcD/middleware-insertion-facade.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import worker, * as OTHER_EXPORTS from "D:\\Code\\VS\\布灵图床\\buling-imgbed-front\\node_modules\\wrangler\\templates\\pages-shim.ts"; | ||
import * as __MIDDLEWARE_0__ from "D:\\Code\\VS\\布灵图床\\buling-imgbed-front\\node_modules\\wrangler\\templates\\middleware\\middleware-ensure-req-body-drained.ts"; | ||
import * as __MIDDLEWARE_1__ from "D:\\Code\\VS\\布灵图床\\buling-imgbed-front\\node_modules\\wrangler\\templates\\middleware\\middleware-miniflare3-json-error.ts"; | ||
|
||
export * from "D:\\Code\\VS\\布灵图床\\buling-imgbed-front\\node_modules\\wrangler\\templates\\pages-shim.ts"; | ||
|
||
export const __INTERNAL_WRANGLER_MIDDLEWARE__ = [ | ||
|
||
__MIDDLEWARE_0__.default,__MIDDLEWARE_1__.default | ||
] | ||
export default worker; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
// This loads all middlewares exposed on the middleware object and then starts | ||
// the invocation chain. The big idea is that we can add these to the middleware | ||
// export dynamically through wrangler, or we can potentially let users directly | ||
// add them as a sort of "plugin" system. | ||
|
||
import ENTRY, { __INTERNAL_WRANGLER_MIDDLEWARE__ } from "D:\\Code\\VS\\布灵图床\\buling-imgbed-front\\.wrangler\\tmp\\bundle-9AtjcD\\middleware-insertion-facade.js"; | ||
import { __facade_invoke__, __facade_register__, Dispatcher } from "D:\\Code\\VS\\布灵图床\\buling-imgbed-front\\node_modules\\wrangler\\templates\\middleware\\common.ts"; | ||
import type { WorkerEntrypointConstructor } from "D:\\Code\\VS\\布灵图床\\buling-imgbed-front\\.wrangler\\tmp\\bundle-9AtjcD\\middleware-insertion-facade.js"; | ||
|
||
// Preserve all the exports from the worker | ||
export * from "D:\\Code\\VS\\布灵图床\\buling-imgbed-front\\.wrangler\\tmp\\bundle-9AtjcD\\middleware-insertion-facade.js"; | ||
|
||
class __Facade_ScheduledController__ implements ScheduledController { | ||
readonly #noRetry: ScheduledController["noRetry"]; | ||
|
||
constructor( | ||
readonly scheduledTime: number, | ||
readonly cron: string, | ||
noRetry: ScheduledController["noRetry"] | ||
) { | ||
this.#noRetry = noRetry; | ||
} | ||
|
||
noRetry() { | ||
if (!(this instanceof __Facade_ScheduledController__)) { | ||
throw new TypeError("Illegal invocation"); | ||
} | ||
// Need to call native method immediately in case uncaught error thrown | ||
this.#noRetry(); | ||
} | ||
} | ||
|
||
function wrapExportedHandler(worker: ExportedHandler): ExportedHandler { | ||
// If we don't have any middleware defined, just return the handler as is | ||
if ( | ||
__INTERNAL_WRANGLER_MIDDLEWARE__ === undefined || | ||
__INTERNAL_WRANGLER_MIDDLEWARE__.length === 0 | ||
) { | ||
return worker; | ||
} | ||
// Otherwise, register all middleware once | ||
for (const middleware of __INTERNAL_WRANGLER_MIDDLEWARE__) { | ||
__facade_register__(middleware); | ||
} | ||
|
||
const fetchDispatcher: ExportedHandlerFetchHandler = function ( | ||
request, | ||
env, | ||
ctx | ||
) { | ||
if (worker.fetch === undefined) { | ||
throw new Error("Handler does not export a fetch() function."); | ||
} | ||
return worker.fetch(request, env, ctx); | ||
}; | ||
|
||
return { | ||
...worker, | ||
fetch(request, env, ctx) { | ||
const dispatcher: Dispatcher = function (type, init) { | ||
if (type === "scheduled" && worker.scheduled !== undefined) { | ||
const controller = new __Facade_ScheduledController__( | ||
Date.now(), | ||
init.cron ?? "", | ||
() => {} | ||
); | ||
return worker.scheduled(controller, env, ctx); | ||
} | ||
}; | ||
return __facade_invoke__(request, env, ctx, dispatcher, fetchDispatcher); | ||
}, | ||
}; | ||
} | ||
|
||
function wrapWorkerEntrypoint( | ||
klass: WorkerEntrypointConstructor | ||
): WorkerEntrypointConstructor { | ||
// If we don't have any middleware defined, just return the handler as is | ||
if ( | ||
__INTERNAL_WRANGLER_MIDDLEWARE__ === undefined || | ||
__INTERNAL_WRANGLER_MIDDLEWARE__.length === 0 | ||
) { | ||
return klass; | ||
} | ||
// Otherwise, register all middleware once | ||
for (const middleware of __INTERNAL_WRANGLER_MIDDLEWARE__) { | ||
__facade_register__(middleware); | ||
} | ||
|
||
// `extend`ing `klass` here so other RPC methods remain callable | ||
return class extends klass { | ||
#fetchDispatcher: ExportedHandlerFetchHandler<Record<string, unknown>> = ( | ||
request, | ||
env, | ||
ctx | ||
) => { | ||
this.env = env; | ||
this.ctx = ctx; | ||
if (super.fetch === undefined) { | ||
throw new Error("Entrypoint class does not define a fetch() function."); | ||
} | ||
return super.fetch(request); | ||
}; | ||
|
||
#dispatcher: Dispatcher = (type, init) => { | ||
if (type === "scheduled" && super.scheduled !== undefined) { | ||
const controller = new __Facade_ScheduledController__( | ||
Date.now(), | ||
init.cron ?? "", | ||
() => {} | ||
); | ||
return super.scheduled(controller); | ||
} | ||
}; | ||
|
||
fetch(request: Request<unknown, IncomingRequestCfProperties>) { | ||
return __facade_invoke__( | ||
request, | ||
this.env, | ||
this.ctx, | ||
this.#dispatcher, | ||
this.#fetchDispatcher | ||
); | ||
} | ||
}; | ||
} | ||
|
||
let WRAPPED_ENTRY: ExportedHandler | WorkerEntrypointConstructor | undefined; | ||
if (typeof ENTRY === "object") { | ||
WRAPPED_ENTRY = wrapExportedHandler(ENTRY); | ||
} else if (typeof ENTRY === "function") { | ||
WRAPPED_ENTRY = wrapWorkerEntrypoint(ENTRY); | ||
} | ||
export default WRAPPED_ENTRY; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
const urls = new Set(); | ||
|
||
function checkURL(request, init) { | ||
const url = | ||
request instanceof URL | ||
? request | ||
: new URL( | ||
(typeof request === "string" | ||
? new Request(request, init) | ||
: request | ||
).url | ||
); | ||
if (url.port && url.port !== "443" && url.protocol === "https:") { | ||
if (!urls.has(url.toString())) { | ||
urls.add(url.toString()); | ||
console.warn( | ||
`WARNING: known issue with \`fetch()\` requests to custom HTTPS ports in published Workers:\n` + | ||
` - ${url.toString()} - the custom port will be ignored when the Worker is published using the \`wrangler deploy\` command.\n` | ||
); | ||
} | ||
} | ||
} | ||
|
||
globalThis.fetch = new Proxy(globalThis.fetch, { | ||
apply(target, thisArg, argArray) { | ||
const [request, init] = argArray; | ||
checkURL(request, init); | ||
return Reflect.apply(target, thisArg, argArray); | ||
}, | ||
}); |
11 changes: 11 additions & 0 deletions
11
.wrangler/tmp/bundle-LEsCS6/middleware-insertion-facade.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import worker, * as OTHER_EXPORTS from "D:\\Code\\VS\\布灵图床\\buling-imgbed-front\\node_modules\\wrangler\\templates\\pages-shim.ts"; | ||
import * as __MIDDLEWARE_0__ from "D:\\Code\\VS\\布灵图床\\buling-imgbed-front\\node_modules\\wrangler\\templates\\middleware\\middleware-ensure-req-body-drained.ts"; | ||
import * as __MIDDLEWARE_1__ from "D:\\Code\\VS\\布灵图床\\buling-imgbed-front\\node_modules\\wrangler\\templates\\middleware\\middleware-miniflare3-json-error.ts"; | ||
|
||
export * from "D:\\Code\\VS\\布灵图床\\buling-imgbed-front\\node_modules\\wrangler\\templates\\pages-shim.ts"; | ||
|
||
export const __INTERNAL_WRANGLER_MIDDLEWARE__ = [ | ||
|
||
__MIDDLEWARE_0__.default,__MIDDLEWARE_1__.default | ||
] | ||
export default worker; |
Oops, something went wrong.