Skip to content

Commit

Permalink
start() returns the replServer
Browse files Browse the repository at this point in the history
  • Loading branch information
pmcelhaney committed Oct 23, 2023
1 parent 4088bc7 commit 09261bb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/server/app.ts
@@ -1,6 +1,6 @@
import nodePath from "node:path";

import { createHttpTerminator, type HttpTerminator } from "http-terminator";
import { createHttpTerminator } from "http-terminator";
import yaml from "js-yaml";
import $RefParser from "json-schema-ref-parser";

Expand All @@ -15,9 +15,6 @@ import { Registry } from "./registry.js";
import { startRepl } from "./repl.js";
import { Transpiler } from "./transpiler.js";

// eslint-disable-next-line @typescript-eslint/init-declarations
let httpTerminator: HttpTerminator | undefined;

async function loadOpenApiDocument(source: string) {
try {
const text = await readFile(source);
Expand Down Expand Up @@ -80,22 +77,26 @@ export async function counterfact(config: Config) {
port: config.port,
});

httpTerminator = createHttpTerminator({
const httpTerminator = createHttpTerminator({
server,
});

startRepl(contextRegistry, config);
}
const replServer = startRepl(contextRegistry, config);

async function stop() {
await stopCounterfact();
await httpTerminator?.terminate();
return {
replServer,

async stop() {
await stopCounterfact();
await httpTerminator.terminate();
},
};
}

return {
contextRegistry,
koaMiddleware: middleware,
registry,
start,
stop,
};
}
2 changes: 2 additions & 0 deletions src/server/repl.ts
Expand Up @@ -55,4 +55,6 @@ export function startRepl(contextRegistry: ContextRegistry, config: Config) {
replServer.context.loadContext = (path: string) => contextRegistry.find(path);
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
replServer.context.context = replServer.context.loadContext("/");

return replServer;
}

0 comments on commit 09261bb

Please sign in to comment.