import * as _homer0_jimple from '@homer0/jimple'; import { J as Jimpex, D as MiddlewareConnectFn } from '../../index-DAUqbQ6h.js'; import { AsyncExpressMiddleware } from '../../types/express.js'; import { SendFile } from '../../services/common/sendFile.js'; import { HTMLGenerator } from '../../services/html/htmlGenerator.js'; import { Response, NextFunction } from 'express'; import '../../types/http.js'; import 'https'; import 'http'; import 'spdy'; import 'node-fetch'; import '../../types/utils.js'; import '@homer0/path-utils'; import '@homer0/simple-logger'; import '@homer0/simple-config'; import '@homer0/events-hub'; import '../../services/frontend/frontendFs.js'; import 'node:fs/promises'; import '@homer0/deferred'; /** * The options to customize the behavior of the middleware. * * @group Middlewares/ShowHTML */ type ShowHTMLOptions = { /** * The name of the file the middleware will serve. If the {@link HTMLGenerator} service * is available, it will be overridden by the service. * * @default 'index.html' */ file: string; }; /** * The options to construct a {@link ShowHTML}. * * @group Middlewares/ShowHTML */ type ShowHTMLConstructorOptions = Partial & { /** * A dictionary with the dependencies to inject. */ inject: { sendFile: SendFile; /** * A function to get a possible {@link HTMLGenerator}. This is injected as a "getter" * to not interrupt the DIC "lifecycle": middlewares are initialized right when the * app starts, and injecting a reference would force the service to be initialized * too, even if a request is not being made. */ getHTMLGenerator?: () => HTMLGenerator | undefined; }; }; /** * The options for the middleware creator that will mount an instance of {@link ShowHTML}. * * @group Middlewares/ShowHTML */ type ShowHTMLMiddlewareOptions = Partial & { /** * The name of an {@link HTMLGenerator} service already available in the application. * * @default 'htmlGenerator' */ htmlGeneratorServiceName?: string; }; /** * A very simple middleware service to send an HTML on a server response. The special * _'feature'_ of this service is that it can be hooked up to an {@link HTMLGenerator} * service and it will automatically server the file generated by it. * * @group Middleware Classes * @group Middlewares/ShowHTML * @prettierignore */ declare class ShowHTML { /** * The service that serves a file. */ protected readonly _sendFile: SendFile; /** * A function to get a possible {@link HTMLGenerator}. This is injected as a "getter" * to not interrupt the DIC "lifecycle": middlewares are initialized right when the * app starts, and injecting a reference would force the service to be initialized * too, even if a request is not being made. */ protected readonly _getHTMLGenerator: () => HTMLGenerator | undefined; /** * The customization options for the middleware. */ protected _options: ShowHTMLOptions; /** * Whether or not the file is ready to be served. In case the middleware uses an * {@link HTMLGenerator} service, the file needs to be generated before being available, * and that's why this flag exists. */ protected _fileReady: boolean; /** * @param options The options to construct the class. */ constructor({ inject, ...options }: ShowHTMLConstructorOptions); /** * Generates the middleware that serves the HTML file. */ getMiddleware(): AsyncExpressMiddleware; /** * The customization options. */ get options(): Readonly; /** * Serves the HTML file to the response. * * @param res The response object generated by the application. * @param next The function to call the next middleware. */ protected _sendResponse(res: Response, next: NextFunction): void; } /** * Creates the middleware that serves an HTML file in the response. * * @group Middlewares * @group Middlewares/ShowHTML */ declare const showHTMLMiddleware: _homer0_jimple.ResourceCreator<"middleware", "connect", (options?: ShowHTMLMiddlewareOptions) => (app: ContainerType) => AsyncExpressMiddleware, MiddlewareConnectFn>; export { ShowHTML, type ShowHTMLConstructorOptions, type ShowHTMLMiddlewareOptions, type ShowHTMLOptions, showHTMLMiddleware };