feat: Add qwik-react (#103)

This adds the following pages:

The landing page (/)
The pricing page (/pricing)
The contact page (/contact)
The changelog page (/changelog)
Terms Of Service page (/terms)
Privacy Policy (/privacy)
This commit is contained in:
Wanjohi
2024-08-30 16:19:58 +03:00
committed by GitHub
parent d13d3dc5d8
commit 73cec51728
102 changed files with 5096 additions and 105 deletions

47
packages/cache/middleware.ts vendored Normal file
View File

@@ -0,0 +1,47 @@
import { kvResponseCache } from "./caches";
import type { Filter } from "./types";
import type { Context, Env, MiddlewareHandler } from "hono";
type Namespace<E extends Env> = string | ((c: Context<E>) => string);
interface GetCacheKey<E extends Env> {
(c: Context<E>): string;
}
type KVCacheOption<E extends Env & { Bindings: Record<string, unknown> }> = {
key: keyof E["Bindings"];
namespace: Namespace<E>;
getCacheKey?: GetCacheKey<E>;
options?: KVNamespacePutOptions;
};
export const defaultGetCacheKey = <E extends Env>(c: Context<E>) => c.req.url;
export const kvCaches =
<E extends Env & { Bindings: Record<string, unknown> }>({
key: bindingKey,
namespace,
options,
getCacheKey = defaultGetCacheKey,
}: KVCacheOption<E>): MiddlewareHandler<E> =>
async (c, next) => {
const kv: KVNamespace = c.env?.[bindingKey] as KVNamespace;
const kvNamespace = typeof namespace === "function" ? namespace(c) : namespace;
const kvCaches = kvResponseCache(kv);
const cache = kvCaches(kvNamespace);
const key = getCacheKey(c);
const response = await cache.match(key);
if (response) {
response.headers.set("X-KV-CACHE", "hit");
return response;
}
await next();
if (c.res.status >= 200 && c.res.status < 300) {
c.executionCtx.waitUntil(cache.put(key, c.res.clone(), options));
}
};