@sentzunhat/zacatl
Version:
A modular, high-performance TypeScript microservice framework for Node.js, featuring layered architecture, dependency injection, and robust validation for building scalable APIs and distributed systems.
40 lines • 1.36 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.FastifyApiAdapter = void 0;
const http_proxy_1 = __importDefault(require("@fastify/http-proxy"));
class FastifyApiAdapter {
server;
constructor(server) {
this.server = server;
}
registerRoute(handler) {
this.server.withTypeProvider().route({
url: handler.url,
method: handler.method,
schema: handler.schema,
handler: handler.execute.bind(handler),
});
}
registerHook(handler) {
this.server.addHook(handler.name, handler.execute.bind(handler));
}
registerProxy(config) {
this.server.register(http_proxy_1.default, {
upstream: config.upstream,
prefix: config.prefix,
...(config.rewritePrefix != null ? { rewritePrefix: config.rewritePrefix } : {}),
...(config.http2 !== undefined ? { http2: config.http2 } : {}),
});
}
async listen(port) {
await this.server.listen({ port, host: '0.0.0.0' });
}
getRawServer() {
return this.server;
}
}
exports.FastifyApiAdapter = FastifyApiAdapter;
//# sourceMappingURL=fastify-adapter.js.map