Yet another Cloudflare framework.
Install @bit-js/quark
with @cloudflare/workers-types
.
npm i @bit-js/quark
npm i @cloudflare/workers-types --dev
An example Hello world
app:
import { Quark } from "@bit-js/quark";
const app = new Quark()
.use((ctx) => {
// TODO: Cache the header if it is static
ctx.headers.push(["Content-Type", "text/plain"]);
return ctx.next();
})
.get("/", (ctx) => ctx.body("Hello world"));
export default app;
To access ExecutionContext
and Env
:
(ctx) => {
// Environment variables
ctx.env;
// Execution context
ctx.execution;
};
To overwrite Env
types:
declare global {
interface Env {
MY_ENV_VAR: string;
MY_SECRET: string;
myKVNamespace: KVNamespace;
}
}
To use Quark
with service workers:
addEventListener("fetch", app.handleEvent);
An example Hello world
app:
import { Quark } from "npm:@bit-js/quark";
const app = new Quark()
.use((ctx) => {
// TODO: Cache the header if it is static
ctx.headers.push(["Content-Type", "text/plain"]);
return ctx.next();
})
.get("/", (ctx) => ctx.body("Hello world"));
export default app;
Install @bit-js/quark
:
npm i @bit-js/quark
An example Hello world
app:
import { Quark } from "@bit-js/quark";
const app = new Quark()
.use((ctx) => {
ctx.headers["Content-Type"] = "text/plain";
return ctx.next();
})
.get("/", (ctx) => ctx.body("Hello world"));
export default app;
Export your app type:
export type TApp = typeof app;
Usage on client:
import type { TApp } from "../server";
import { client } from "@bit-js/quark";
const app = client<TApp>("http://localhost:3000");
const res = await app.get("/");
await res.text(); // Hello world