mirror of
https://github.com/ReCloudStudio/WebHooker.git
synced 2026-09-22 16:11:29 +00:00
feat: migrate to Nuxt 4 (Nitro) and Tailwind CSS v3
This commit is contained in:
parent
f4959eebf8
commit
b139712a91
166 changed files with 19790 additions and 5539 deletions
39
server/lib/cf.ts
Normal file
39
server/lib/cf.ts
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
import type { H3Event } from "h3";
|
||||
import type { Env } from "./types";
|
||||
|
||||
/**
|
||||
* Cloudflare bindings (KV, D1, secrets) from the request context. Works on
|
||||
* Cloudflare Workers (fetch and scheduled) and in tests that stub
|
||||
* `event.context.cloudflare`. Throws with a clear message in other runtimes.
|
||||
*/
|
||||
export function cfEnv(event: H3Event): Env {
|
||||
const env = (event.context.cloudflare as { env?: Env } | undefined)?.env;
|
||||
if (!env) {
|
||||
throw new Error("Cloudflare bindings unavailable — run via wrangler dev/deploy");
|
||||
}
|
||||
return env;
|
||||
}
|
||||
|
||||
/** `waitUntil` from the CF execution context (no-op outside workers). */
|
||||
export function cfWaitUntil(event: H3Event): (promise: Promise<unknown>) => void {
|
||||
const cloudflare = event.context.cloudflare as
|
||||
| {
|
||||
ctx?: { waitUntil?: (p: Promise<unknown>) => void };
|
||||
context?: { waitUntil?: (p: Promise<unknown>) => void };
|
||||
}
|
||||
| undefined;
|
||||
const waitUntil =
|
||||
(event.context.waitUntil as ((p: Promise<unknown>) => void) | undefined) ??
|
||||
cloudflare?.context?.waitUntil ??
|
||||
cloudflare?.ctx?.waitUntil;
|
||||
return waitUntil ? waitUntil.bind(event.context) : () => undefined;
|
||||
}
|
||||
|
||||
/** Lowercased request headers (the provider detection reads lowercase keys). */
|
||||
export function headersFrom(event: H3Event): Record<string, string> {
|
||||
const out: Record<string, string> = {};
|
||||
event.headers.forEach((value, key) => {
|
||||
out[key.toLowerCase()] = value;
|
||||
});
|
||||
return out;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue