fix: patch @sveltejs/adapter-cloudflare
All checks were successful
deploy to cloudflare pages / deploy (push) Successful in 33s

see https://github.com/sveltejs/kit/issues/12305
This commit is contained in:
uku 2024-10-26 11:59:26 +02:00
parent c2e36adc6a
commit 111b9c4ff0
Signed by: uku
SSH key fingerprint: SHA256:4P0aN6M8ajKukNi6aPOaX0LacanGYtlfjmN+m/sHY/o
3 changed files with 62 additions and 2 deletions

View file

@ -0,0 +1,57 @@
diff --git a/index.js b/index.js
index 0fe55898e5697fc6a061299780e163ca4553cb05..e9fb7fea0082c7d3df7b07df21bd99cca6c4957c 100644
--- a/index.js
+++ b/index.js
@@ -144,29 +144,33 @@ export default function (options = {}) {
);
}
},
- async emulate() {
- const proxy = await getPlatformProxy(options.platformProxy);
- const platform = /** @type {App.Platform} */ ({
- env: proxy.env,
- context: proxy.ctx,
- caches: proxy.caches,
- cf: proxy.cf
- });
+ emulate() {
+ const getting_platform = (async () => {
+ const proxy = await getPlatformProxy(options.platformProxy);
+ const platform = /** @type {App.Platform} */ ({
+ env: proxy.env,
+ context: proxy.ctx,
+ caches: proxy.caches,
+ cf: proxy.cf
+ });
- /** @type {Record<string, any>} */
- const env = {};
- const prerender_platform = /** @type {App.Platform} */ (/** @type {unknown} */ ({ env }));
+ /** @type {Record<string, any>} */
+ const env = {};
+ const prerender_platform = /** @type {App.Platform} */ (/** @type {unknown} */ ({ env }));
- for (const key in proxy.env) {
- Object.defineProperty(env, key, {
- get: () => {
- throw new Error(`Cannot access platform.env.${key} in a prerenderable route`);
- }
- });
- }
+ for (const key in proxy.env) {
+ Object.defineProperty(env, key, {
+ get: () => {
+ throw new Error(`Cannot access platform.env.${key} in a prerenderable route`);
+ }
+ });
+ }
+ return { platform, prerender_platform };
+ })();
return {
- platform: ({ prerender }) => {
+ platform: async ({ prerender }) => {
+ const { platform, prerender_platform } = await getting_platform;
return prerender ? prerender_platform : platform;
}
};