0.1.3•Updated 6 months ago
import InfinityHeaders from "@infinity-beyond/modules/networking/infinity_headers.ts";
export interface SendOptions {
status?: number,
headers?: Headers | Record<string, string>
}
export type Send = (body?: string, options?: SendOptions) => void
export type JSON = (body?: Record<string, any>, options?: SendOptions) => void
export const send: Send = (body, { status, headers } = {}) => {
return new Response(body, {
status,
headers: InfinityHeaders.concat(headers),
})
};
export const json: JSON = (body, { status, headers } = {} ) => {
return new Response(JSON.stringify(body), {
status,
headers: InfinityHeaders.concat(headers, {
'Content-Type': 'application/json'
})
})
};
// TODO: Consider whether any of this is really necessary?