UNPKG

@thisisagile/easy-service

Version:

Straightforward library for building domain-driven microservice architectures

28 lines (27 loc) 972 B
import "../chunk-4N72FQFX.mjs"; // src/resources/Service.ts import { Enum, toList, tryTo } from "@thisisagile/easy"; var Service = class extends Enum { constructor(name, app, resources = toList()) { super(name); this.name = name; this.app = app; this.resources = resources; } port = 8080; pre = () => []; post = () => []; with(...resources) { return tryTo(this).accept((t) => t.resources.add(resources.map((r) => new r()))).value; } atPort(port) { return tryTo(this).accept((t) => t.port = port).value; } start(message = `Service ${this.name} listening on port ${this.port} with ${this.resources.length} resources.`) { tryTo(this).accept((t) => t.pre().forEach((h) => this.app.use(h))).accept((t) => t.resources.forEach((r) => this.app.route(this, r))).accept((t) => t.post().forEach((h) => this.app.use(h))).accept((t) => t.app.listen(this.port, message)); } }; export { Service }; //# sourceMappingURL=Service.mjs.map