UNPKG

@uisap/core

Version:

A modular Fastify-based framework inspired by Laravel

43 lines (41 loc) 1.43 kB
import { ServiceProvider } from "../serviceProvider.js"; import { Route } from "../routing.js"; export class RouteProvider extends ServiceProvider { register() { // Tüm rotaları container'a bağla (api, channels, console) this.app.container.singleton("routes", () => ({ api: this.app.config.routes?.api || null, channels: this.app.config.routes?.channels || null, console: this.app.config.routes?.console || null, })); this.app.fastify.decorate( "Route", Route(this.app.fastify, this.app.container) ); this.app.fastify.logger.debug("RouteProvider registered", { routes: Object.keys(this.app.config.routes || {}), }); } async boot() { const routes = this.app.container.make("routes"); if (!this.app.fastify.logger) { this.app.fastify.logger.error( "fastify.logger undefined, yeniden bağlanıyor" ); this.app.fastify.decorate("logger", this.app.container.make("logger")); } // Tüm rotaları çalıştır if (routes.api) { await routes.api(this.app.fastify); this.app.fastify.logger.debug("API rotaları yüklendi"); } if (routes.channels) { await routes.channels(this.app); this.app.fastify.logger.debug("Kanal rotaları yüklendi"); } if (routes.console) { await routes.console(this.app); this.app.fastify.logger.debug("Konsol rotaları yüklendi"); } } }