0.1.1•Updated 7 months ago
import { type InfinityRequest } from "@infinity-beyond/modules/networking/infinity_request.ts";
interface I_SendOptions {
status?: number
}
export class InfinityResponse {
req: InfinityRequest
get ctx() {
return this.req.ctx;
}
constructor(req: InfinityRequest) {
this.req = req;
}
private default_headers() {
this.ctx.response.headers.set('X-Powered-By', 'InfinityBeyond::')
}
send(body: string, { status }: I_SendOptions = {}) {
this.ctx.respond = true;
this.ctx.response.status = status ?? 200;
this.ctx.response.body = body;
}
json(body: Record<string, any>, { status }: I_SendOptions = {} ) {
this.ctx.respond = true;
this.ctx.response.status = status ?? 200;
this.ctx.response.body = JSON.stringify(body);
this.ctx.response.headers.set('Content-Type', 'application/json');
}
}