diff --git a/deployed_final.html b/deployed_final.html new file mode 100644 index 0000000..58c284d --- /dev/null +++ b/deployed_final.html @@ -0,0 +1,46 @@ + + + + + + + PixivNow + + + + + + + + + + + + + + + + +
+ + diff --git a/functions/[[path]].ts b/functions/[[path]].ts index bf44bed..a5a1b5b 100644 --- a/functions/[[path]].ts +++ b/functions/[[path]].ts @@ -59,28 +59,25 @@ export default { } // 静态资源和前端页面处理 - // 使用新的 Assets API - if (env.ASSETS) { - try { - return await env.ASSETS.fetch(request) - } catch (e) { - console.log('Asset not found, falling back to index.html') - // 如果静态资源不存在,返回 index.html(SPA 路由处理) - try { - const indexRequest = new Request(new URL('/index.html', request.url), request) - return await env.ASSETS.fetch(indexRequest) - } catch (indexError) { - console.log('Index.html not found, using fallback') - // 如果 index.html 也不存在,返回内置的前端页面 - return await handleFrontendPage(request, env) + // 使用 getAssetFromKV (Workers Sites) + try { + return await getAssetFromKV( + { + request, + waitUntil: ctx.waitUntil.bind(ctx), + }, + { + ASSET_NAMESPACE: env.__STATIC_CONTENT, + ASSET_MANIFEST: env.__STATIC_CONTENT_MANIFEST, } - } - } else { - // 如果没有 ASSETS,使用 getAssetFromKV + ) + } catch (e) { + // 如果静态资源不存在,返回 index.html(SPA 路由处理) try { + const indexRequest = new Request(new URL('/index.html', request.url), request) return await getAssetFromKV( { - request, + request: indexRequest, waitUntil: ctx.waitUntil.bind(ctx), }, { @@ -88,24 +85,9 @@ export default { ASSET_MANIFEST: env.__STATIC_CONTENT_MANIFEST, } ) - } catch (e) { - // 如果静态资源不存在,返回 index.html(SPA 路由处理) - try { - const indexRequest = new Request(new URL('/index.html', request.url), request) - return await getAssetFromKV( - { - request: indexRequest, - waitUntil: ctx.waitUntil.bind(ctx), - }, - { - ASSET_NAMESPACE: env.__STATIC_CONTENT, - ASSET_MANIFEST: env.__STATIC_CONTENT_MANIFEST, - } - ) - } catch (indexError) { - // 如果 index.html 也不存在,返回内置的前端页面 - return await handleFrontendPage(request, env) - } + } catch (indexError) { + // 如果 index.html 也不存在,返回内置的前端页面 + return await handleFrontendPage(request, env) } } diff --git a/wrangler.toml b/wrangler.toml index e06e70c..a11b537 100644 --- a/wrangler.toml +++ b/wrangler.toml @@ -2,9 +2,9 @@ name = "pixivnow-worker" main = "functions/[[path]].ts" compatibility_date = "2023-10-30" -# Assets 配置 - 用于部署静态资源 -[assets] -directory = "./dist" +# Workers Sites 配置 - 用于部署静态资源 +[site] +bucket = "./dist" # 环境变量配置 # 这些变量都有默认值,可以根据需要自定义