tezx
Version:
TezX is a modern, ultra-lightweight, and high-performance JavaScript framework built specifically for Bun. It provides a minimal yet powerful API, seamless environment management, and a high-concurrency HTTP engine for building fast, scalable web applicat
30 lines (29 loc) • 875 B
JavaScript
export let notFoundResponse = (ctx) => {
const { method, pathname } = ctx;
return ctx.text(`${method}: '${pathname}' could not find\n`, {
status: 404,
});
};
export function mergeHeaders(existing, init) {
if (!existing)
return new Headers(init);
if (!init)
return existing;
const out = new Headers(existing);
for (const key in init) {
const val = init[key];
if (val && key.toLowerCase() === "set-cookie") {
out.append(key, val);
}
else if (val) {
out.set(key, val);
}
}
return out;
}
export async function handleErrorResponse(err = new Error("Internal Server Error"), ctx) {
if (err instanceof Error) {
return ctx.status(500).text(err.message ?? "Internal Server Error");
}
return await handleErrorResponse(new Error(err), ctx);
}