From 731a307bdacc7f9bf99b82bac0d3ccc5e94d802f Mon Sep 17 00:00:00 2001 From: Daniel Huber Date: Wed, 8 Sep 2021 17:44:58 +0000 Subject: [PATCH 1/2] Implement `localhost` default address for IntelliJ service config The IntelliJ schema mentions that it defaults to `127.0.0.1:19524` if no address is given. This makes sense as most will connect the service to the IntelliJ instance running on the same host. However the schema requires a value and also the code doesn't check for `undefined` and thus doesn't provide the default if the value is missing. This PR implements the default value by using it if no value is provided and removing `address` from the required fields list of the JSON schema. --- nodecg-io-intellij/extension/index.ts | 5 ++--- nodecg-io-intellij/extension/intellij.ts | 8 ++++---- nodecg-io-intellij/intellij-schema.json | 2 +- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/nodecg-io-intellij/extension/index.ts b/nodecg-io-intellij/extension/index.ts index a6d83e0db..0b7351b11 100644 --- a/nodecg-io-intellij/extension/index.ts +++ b/nodecg-io-intellij/extension/index.ts @@ -3,7 +3,7 @@ import { Result, emptySuccess, success, ServiceBundle } from "nodecg-io-core"; import { IntelliJ } from "./intellij"; interface IntelliJServiceConfig { - address: string; + address?: string; } export type IntelliJServiceClient = IntelliJ; @@ -14,8 +14,7 @@ module.exports = (nodecg: NodeCG) => { class IntellijService extends ServiceBundle { async validateConfig(config: IntelliJServiceConfig): Promise> { - const address = config.address; - const ij = new IntelliJ(address); + const ij = new IntelliJ(config.address); await ij.rawRequest("available_methods", {}); return emptySuccess(); } diff --git a/nodecg-io-intellij/extension/intellij.ts b/nodecg-io-intellij/extension/intellij.ts index 850471d0e..ecc87365d 100644 --- a/nodecg-io-intellij/extension/intellij.ts +++ b/nodecg-io-intellij/extension/intellij.ts @@ -6,12 +6,12 @@ export class IntelliJ { readonly pluginManager: PluginManager; readonly localHistory: LocalHistory; - public constructor(address: string) { - this.address = address; - if (address.includes("://")) { + constructor(address?: string) { + // Check if protocol is defined and default to http if missing + if (address?.includes("://")) { this.address = address; } else { - this.address = "http://" + address; + this.address = `http://${address ?? "127.0.0.1:19524"}`; } this.pluginManager = new PluginManager(this); diff --git a/nodecg-io-intellij/intellij-schema.json b/nodecg-io-intellij/intellij-schema.json index 9d6b14769..cdd1b5598 100644 --- a/nodecg-io-intellij/intellij-schema.json +++ b/nodecg-io-intellij/intellij-schema.json @@ -8,5 +8,5 @@ "description": "The address where the nodecg-io-intellij server runs. This defaults to 127.0.0.1:19524" } }, - "required": ["address"] + "required": [] } From 4e3169b599245d302feff48b18e5588637d0646d Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 8 Sep 2021 20:28:38 +0200 Subject: [PATCH 2/2] Show actual address in intellij connection success message instead of address in config --- nodecg-io-intellij/extension/index.ts | 2 +- nodecg-io-intellij/extension/intellij.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/nodecg-io-intellij/extension/index.ts b/nodecg-io-intellij/extension/index.ts index 0b7351b11..6988db275 100644 --- a/nodecg-io-intellij/extension/index.ts +++ b/nodecg-io-intellij/extension/index.ts @@ -22,7 +22,7 @@ class IntellijService extends ServiceBundle> { const ij = new IntelliJ(config.address); await ij.rawRequest("available_methods", {}); - this.nodecg.log.info(`Successfully connected to IntelliJ at ${config.address}.`); + this.nodecg.log.info(`Successfully connected to IntelliJ at ${ij.address}.`); return success(ij); } diff --git a/nodecg-io-intellij/extension/intellij.ts b/nodecg-io-intellij/extension/intellij.ts index ecc87365d..11b8545e5 100644 --- a/nodecg-io-intellij/extension/intellij.ts +++ b/nodecg-io-intellij/extension/intellij.ts @@ -1,7 +1,7 @@ import fetch from "node-fetch"; export class IntelliJ { - private readonly address: string; + readonly address: string; readonly pluginManager: PluginManager; readonly localHistory: LocalHistory;