@mini2/core
Version:
Mini Express Framework - Lightweight and modular Express.js framework with TypeScript support
45 lines • 1.12 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ResponseBuilder = void 0;
class ResponseBuilder {
constructor() {
this.status = 200;
this.headers = {};
this.isFile = false;
}
ok(data) {
this.status = 200;
this.data = data;
return this;
}
created(data) {
this.status = 201;
this.data = data;
return this;
}
setHeader(key, value) {
this.headers[key] = value;
return this;
}
setHeaders(headers) {
this.headers = { ...this.headers, ...headers };
return this;
}
asFile() {
this.isFile = true;
return this;
}
build(res) {
Object.entries(this.headers).forEach(([key, value]) => {
res.setHeader(key, value);
});
if (this.isFile && this.data) {
res.status(this.status).send(this.data);
}
else {
res.status(this.status).json(this.data);
}
}
}
exports.ResponseBuilder = ResponseBuilder;
//# sourceMappingURL=response-builder.js.map