cairo/lib/Cairo.ts

33 lines
1.3 KiB
TypeScript
Raw Normal View History

2024-08-24 12:41:04 -06:00
// Import Core Modules
import { INFO, OK, logInfo } from "@dunemask/vix/logging";
import { Vixpress } from "@dunemask/vix";
import { MappedRoute, routePreviews } from "@dunemask/vix/express";
import figlet from "figlet";
import AppRouter from "./vix/AppRouter.js";
import PostgresService from "./database/PostgresService.js";
import AppInitService from "./services/app-init.service.js";
export default class Cairo extends Vixpress {
static PostgresService: string = "pg";
static AppInitService: string = "app-init";
constructor(port?: number) {
super("Cairo", port ?? Number(process.env.CAIRO_DEV_PORT ?? 52000));
this.setService(Cairo.PostgresService, PostgresService);
this.setService(Cairo.AppInitService, AppInitService);
this.setRouter(AppRouter);
}
protected async preconfigure(): Promise<void> {
logInfo(figlet.textSync(this.title, "Cosmike"));
}
protected async onStart() {
const previews = routePreviews(this.app, (r: MappedRoute, methodDisplay: string) => {
const authSection = r.routeMetadata?.authType === "user" ? "🔒" : " ";
return `${methodDisplay} ${authSection} ${r.path}`;
});
for (const p of previews) INFO("ROUTE", p);
OK("SERVER", `${this.title} server running on ${this.port} 🚀`);
}
}