Add support to ignoreSSL config option

This commit is contained in:
2024-11-17 14:41:14 +01:00
parent c82234710f
commit beff0a2f35
2 changed files with 9 additions and 2 deletions

View File

@@ -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<OpenHABConfig>) {
constructor({ baseURL, token, ignoreSSL }: Partial<OpenHABConfig>) {
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)}`

View File

@@ -1,6 +1,7 @@
export type OpenHABConfig = {
baseURL: string;
token: string;
ignoreSSL?: boolean;
};
export type Thing = {