UNPKG

@busy-hour/blaze

Version:

<h1 align='center'>🔥 Blaze</h1> <div align='center'> An event driven framework for 🔥 Hono.js </div>

38 lines (37 loc) • 998 B
// src/loader/initializer.ts import fs from "node:fs"; import { BlazeContext } from "../internal/context/index.js"; import { Logger } from "../internal/logger/index.js"; import { BlazeService } from "./service.js"; async function initializeServices(options) { const { app, path: sourcePath } = options; if (!fs.existsSync(sourcePath)) { throw Logger.throw("Service path doesn't exist"); } const ctx = new BlazeContext({ body: null, params: null, headers: null, honoCtx: null, meta: null, query: null }); const serviceFiles = fs.readdirSync(sourcePath); const middlewares = options.middlewares ?? []; const pendingServices = await Promise.all( serviceFiles.map((servicePath) => { const service = BlazeService.create({ app, servicePath, ctx, sourcePath, middlewares }); return service; }) ); pendingServices.forEach((service) => service.onStarted()); } export { initializeServices };