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 axios, { AxiosInstance } from "axios";
|
||||||
|
import { OpenHABConfig, Thing } from "@types";
|
||||||
import { enhancedStringConfig } from "../utils/config";
|
import { enhancedStringConfig } from "../utils/config";
|
||||||
|
|
||||||
export class OpenHAB {
|
export class OpenHAB {
|
||||||
#api: AxiosInstance;
|
#api: AxiosInstance;
|
||||||
|
|
||||||
constructor({ baseURL, token }: Partial<OpenHABConfig>) {
|
constructor({ baseURL, token, ignoreSSL }: Partial<OpenHABConfig>) {
|
||||||
if (!baseURL || !token) {
|
if (!baseURL || !token) {
|
||||||
throw new Error(`Both 'baseURL' and 'token' properties are required on OpenHAB configuration.`);
|
throw new Error(`Both 'baseURL' and 'token' properties are required on OpenHAB configuration.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const httpsAgent = new Agent({
|
||||||
|
rejectUnauthorized: !ignoreSSL
|
||||||
|
});
|
||||||
|
|
||||||
this.#api = axios.create({
|
this.#api = axios.create({
|
||||||
|
httpsAgent,
|
||||||
baseURL: `${baseURL}/rest`,
|
baseURL: `${baseURL}/rest`,
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${enhancedStringConfig(token)}`
|
Authorization: `Bearer ${enhancedStringConfig(token)}`
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
export type OpenHABConfig = {
|
export type OpenHABConfig = {
|
||||||
baseURL: string;
|
baseURL: string;
|
||||||
token: string;
|
token: string;
|
||||||
|
ignoreSSL?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type Thing = {
|
export type Thing = {
|
||||||
|
|||||||
Reference in New Issue
Block a user