UNPKG

@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.

76 lines 2.3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PageServer = void 0; const error_1 = require("../../../../error/index.js"); class PageServer { config; adapter; constructor(config, adapter) { this.config = config; this.adapter = adapter; } registerStaticFiles(config) { try { this.adapter.registerStaticFiles(config); } catch (error) { throw new error_1.CustomError({ message: 'failed to register static files', code: 500, reason: 'static file registration failed', error: error, metadata: { config }, }); } } registerSpaFallback(apiPrefix, staticDir) { try { this.adapter.registerSpaFallback(apiPrefix, staticDir); } catch (error) { throw new error_1.CustomError({ message: 'failed to register SPA fallback', code: 500, reason: 'SPA fallback registration failed', error: error, metadata: { apiPrefix, staticDir }, }); } } async register(server) { try { await this.adapter.register(server); } catch (error) { throw new error_1.CustomError({ message: 'failed to register page module', code: 500, reason: 'page module registration failed', error: error, }); } } async configure() { if (this.config.page == null) { return; } const { staticDir, apiPrefix, customRegister } = this.config.page; if (staticDir != null) { this.registerStaticFiles({ root: staticDir, ...(apiPrefix != null ? { prefix: apiPrefix } : {}), }); } if (staticDir != null && apiPrefix != null) { this.registerSpaFallback(apiPrefix, staticDir); } if (customRegister != null) { await customRegister(this.adapter); } } getAdapter() { return this.adapter; } } exports.PageServer = PageServer; //# sourceMappingURL=page-server.js.map