Website Structure
This commit is contained in:
parent
62812f2090
commit
71f0676a62
22365 changed files with 4265753 additions and 791 deletions
84
Frontend-Learner/node_modules/nitropack/dist/presets/cloudflare/runtime/plugin.dev.mjs
generated
vendored
Normal file
84
Frontend-Learner/node_modules/nitropack/dist/presets/cloudflare/runtime/plugin.dev.mjs
generated
vendored
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
import { useRuntimeConfig, getRequestURL } from "#imports";
|
||||
const proxy = await _getPlatformProxy().catch((error) => {
|
||||
console.error("Failed to initialize wrangler bindings proxy", error);
|
||||
return _createStubProxy();
|
||||
});
|
||||
globalThis.__env__ = proxy.env;
|
||||
globalThis.__wait_until__ = proxy.ctx.waitUntil.bind(proxy.ctx);
|
||||
export default (function(nitroApp) {
|
||||
nitroApp.hooks.hook("request", async (event) => {
|
||||
event.context.cf = proxy.cf;
|
||||
event.context.waitUntil = proxy.ctx.waitUntil.bind(proxy.ctx);
|
||||
const request = new Request(getRequestURL(event));
|
||||
request.cf = proxy.cf;
|
||||
event.context.cloudflare = {
|
||||
...event.context.cloudflare,
|
||||
request,
|
||||
env: proxy.env,
|
||||
context: proxy.ctx
|
||||
};
|
||||
event.node.req.__unenv__ = {
|
||||
...event.node.req.__unenv__,
|
||||
waitUntil: event.context.waitUntil
|
||||
};
|
||||
});
|
||||
nitroApp.hooks._hooks.request.unshift(nitroApp.hooks._hooks.request.pop());
|
||||
nitroApp.hooks.hook("close", () => {
|
||||
return proxy?.dispose();
|
||||
});
|
||||
});
|
||||
async function _getPlatformProxy() {
|
||||
const _pkg = "wrangler";
|
||||
const { getPlatformProxy } = await import(_pkg).catch(() => {
|
||||
throw new Error(
|
||||
"Package `wrangler` not found, please install it with: `npx nypm@latest add -D wrangler`"
|
||||
);
|
||||
});
|
||||
const runtimeConfig = useRuntimeConfig();
|
||||
const proxyOptions = {
|
||||
configPath: runtimeConfig.wrangler.configPath,
|
||||
persist: { path: runtimeConfig.wrangler.persistDir }
|
||||
};
|
||||
if (runtimeConfig.wrangler.environment) {
|
||||
proxyOptions.environment = runtimeConfig.wrangler.environment;
|
||||
}
|
||||
const proxy2 = await getPlatformProxy(proxyOptions);
|
||||
return proxy2;
|
||||
}
|
||||
function _createStubProxy() {
|
||||
return {
|
||||
env: {},
|
||||
cf: {},
|
||||
ctx: {
|
||||
waitUntil() {
|
||||
},
|
||||
passThroughOnException() {
|
||||
},
|
||||
props: {}
|
||||
},
|
||||
caches: {
|
||||
open() {
|
||||
const result = Promise.resolve(new _CacheStub());
|
||||
return result;
|
||||
},
|
||||
get default() {
|
||||
return new _CacheStub();
|
||||
}
|
||||
},
|
||||
dispose: () => Promise.resolve()
|
||||
};
|
||||
}
|
||||
class _CacheStub {
|
||||
delete() {
|
||||
const result = Promise.resolve(false);
|
||||
return result;
|
||||
}
|
||||
match() {
|
||||
const result = Promise.resolve(void 0);
|
||||
return result;
|
||||
}
|
||||
put() {
|
||||
const result = Promise.resolve();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue