Skip to content

Commit

Permalink
print appropriate status message when the proxy URL is not set
Browse files Browse the repository at this point in the history
  • Loading branch information
pmcelhaney committed May 22, 2024
1 parent 42f6336 commit faed043
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion bin/counterfact.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ async function main(source, destination) {
openApiPath: source,
port: options.port,
proxyPaths: new Map([["", Boolean(options.proxyUrl)]]),
proxyUrl: options.proxyUrl,
proxyUrl: options.proxyUrl ?? "",
routePrefix: options.prefix,
startRepl: options.repl,
startServer: options.serve,
Expand Down
7 changes: 7 additions & 0 deletions src/repl/repl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,14 @@ export function startRepl(
config: Config,
print = printToStdout,
) {
// eslint-disable-next-line max-statements
function printProxyStatus() {
if (config.proxyUrl === "") {
print("The proxy URL is not set.");
print('To set it, type ".proxy url <url>');
return;
}

print("Proxy Configuration:");
print("");
print(`The proxy URL is ${config.proxyUrl}`);
Expand Down
16 changes: 16 additions & 0 deletions test/repl/repl.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,22 @@ describe("REPL", () => {
expect(harness.isReset()).toBe(true);
});

it("shows the proxy status when no URL is set", () => {
const { config, harness } = createHarness();

config.proxyUrl = "";
config.proxyPaths.set("/foo", true);
config.proxyPaths.set("/foo/bar", false);

harness.call("proxy", "status");

expect(harness.output).toEqual([
"The proxy URL is not set.",
'To set it, type ".proxy url <url>',
]);
expect(harness.isReset()).toBe(true);
});

it("displays an explanatory message after turning the proxy on for an endpoint", () => {
const { harness } = createHarness();
harness.call("proxy", "on /foo/bar");
Expand Down

0 comments on commit faed043

Please sign in to comment.