diff --git a/src/openhab/index.ts b/src/openhab/index.ts index 93a16a9..9cec4f4 100644 --- a/src/openhab/index.ts +++ b/src/openhab/index.ts @@ -1,16 +1,22 @@ -import { OpenHABConfig, Thing } from "@types"; +import { Agent } from "https"; import axios, { AxiosInstance } from "axios"; +import { OpenHABConfig, Thing } from "@types"; import { enhancedStringConfig } from "../utils/config"; export class OpenHAB { #api: AxiosInstance; - constructor({ baseURL, token }: Partial) { + constructor({ baseURL, token, ignoreSSL }: Partial) { if (!baseURL || !token) { throw new Error(`Both 'baseURL' and 'token' properties are required on OpenHAB configuration.`); } + const httpsAgent = new Agent({ + rejectUnauthorized: !ignoreSSL + }); + this.#api = axios.create({ + httpsAgent, baseURL: `${baseURL}/rest`, headers: { Authorization: `Bearer ${enhancedStringConfig(token)}` diff --git a/src/types/openhab.ts b/src/types/openhab.ts index 57eea43..db8b199 100644 --- a/src/types/openhab.ts +++ b/src/types/openhab.ts @@ -1,6 +1,7 @@ export type OpenHABConfig = { baseURL: string; token: string; + ignoreSSL?: boolean; }; export type Thing = {