Add support to ignoreSSL config option
This commit is contained in:
@@ -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)}`
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
export type OpenHABConfig = {
|
||||
baseURL: string;
|
||||
token: string;
|
||||
ignoreSSL?: boolean;
|
||||
};
|
||||
|
||||
export type Thing = {
|
||||
|
||||
Reference in New Issue
Block a user