Skip to content

Commit bd89080

Browse files
committed
cloudflare workers
1 parent a8a8f75 commit bd89080

File tree

1 file changed

+23
-19
lines changed
  • packages/adapter-cloudflare-workers

1 file changed

+23
-19
lines changed

packages/adapter-cloudflare-workers/index.js

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -149,29 +149,33 @@ export default function ({ config = 'wrangler.toml', platformProxy = {} } = {})
149149
builder.writePrerendered(bucket_dir);
150150
},
151151

152-
async emulate() {
153-
const proxy = await getPlatformProxy(platformProxy);
154-
const platform = /** @type {App.Platform} */ ({
155-
env: proxy.env,
156-
context: proxy.ctx,
157-
caches: proxy.caches,
158-
cf: proxy.cf
159-
});
152+
emulate() {
153+
const getting_platform = (async () => {
154+
const proxy = await getPlatformProxy(platformProxy);
155+
const platform = /** @type {App.Platform} */ ({
156+
env: proxy.env,
157+
context: proxy.ctx,
158+
caches: proxy.caches,
159+
cf: proxy.cf
160+
});
160161

161-
/** @type {Record<string, any>} */
162-
const env = {};
163-
const prerender_platform = /** @type {App.Platform} */ (/** @type {unknown} */ ({ env }));
162+
/** @type {Record<string, any>} */
163+
const env = {};
164+
const prerender_platform = /** @type {App.Platform} */ (/** @type {unknown} */ ({ env }));
164165

165-
for (const key in proxy.env) {
166-
Object.defineProperty(env, key, {
167-
get: () => {
168-
throw new Error(`Cannot access platform.env.${key} in a prerenderable route`);
169-
}
170-
});
171-
}
166+
for (const key in proxy.env) {
167+
Object.defineProperty(env, key, {
168+
get: () => {
169+
throw new Error(`Cannot access platform.env.${key} in a prerenderable route`);
170+
}
171+
});
172+
}
173+
return { platform, prerender_platform };
174+
})();
172175

173176
return {
174-
platform: ({ prerender }) => {
177+
platform: async ({ prerender }) => {
178+
const { platform, prerender_platform } = await getting_platform;
175179
return prerender ? prerender_platform : platform;
176180
}
177181
};

0 commit comments

Comments
 (0)