/**
 * HTTP server factory for gxwf-web.
 *
 * Creates a Node.js http.Server wired to the contents/workflow request handler.
 * Returns a `ready` promise that resolves once the ToolCache is loaded and
 * initial workflow discovery completes — callers may await it before serving
 * traffic but the server is safe to bind before that.
 */
import { createServer } from "node:http";
import { makeNodeToolInfoService } from "@galaxy-tool-util/core/node";
import { createRequestHandler } from "./router.js";
import { discoverWorkflows } from "./workflows.js";
/** Create a configured gxwf-web HTTP server for the given workflow directory. */
export function createApp(directory, opts = {}) {
    const service = makeNodeToolInfoService({
        cacheDir: opts.cacheDir,
        sources: opts.sources,
    });
    const state = {
        directory,
        cache: service.cache,
        infoService: service,
        workflows: { directory, workflows: [] },
        cacheDir: opts.cacheDir,
        uiDir: opts.uiDir,
        extraConnectSrc: opts.extraConnectSrc,
    };
    const handler = createRequestHandler(state);
    const server = createServer((req, res) => {
        void handler(req, res);
    });
    const ready = (async () => {
        await service.cache.index.load();
        state.workflows = discoverWorkflows(directory);
    })();
    return { server, state, ready };
}
//# sourceMappingURL=app.js.map