Merge pull request #482 from danditomaso/issue-481-node-connecting-on-https
fix: update TLS setting if URL is using HTTPS Fixes #481
This commit is contained in:
@@ -11,7 +11,6 @@ import { MeshDevice } from "@meshtastic/core";
|
|||||||
import { TransportHTTP } from "@meshtastic/transport-http";
|
import { TransportHTTP } from "@meshtastic/transport-http";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { useForm, useController } from "react-hook-form";
|
import { useForm, useController } from "react-hook-form";
|
||||||
import { FieldWrapper } from "@components/Form/FormWrapper.tsx";
|
|
||||||
|
|
||||||
interface FormData {
|
interface FormData {
|
||||||
ip: string;
|
ip: string;
|
||||||
@@ -19,8 +18,11 @@ interface FormData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const HTTP = ({ closeDialog }: TabElementProps) => {
|
export const HTTP = ({ closeDialog }: TabElementProps) => {
|
||||||
|
const isURLHTTPS = location.protocol === "https:";
|
||||||
|
|
||||||
const { addDevice } = useDeviceStore();
|
const { addDevice } = useDeviceStore();
|
||||||
const { setSelectedDevice } = useAppStore();
|
const { setSelectedDevice } = useAppStore();
|
||||||
|
|
||||||
const { control, handleSubmit, register } = useForm<FormData>({
|
const { control, handleSubmit, register } = useForm<FormData>({
|
||||||
defaultValues: {
|
defaultValues: {
|
||||||
ip: ["client.meshtastic.org", "localhost"].includes(
|
ip: ["client.meshtastic.org", "localhost"].includes(
|
||||||
@@ -28,7 +30,7 @@ export const HTTP = ({ closeDialog }: TabElementProps) => {
|
|||||||
)
|
)
|
||||||
? "meshtastic.local"
|
? "meshtastic.local"
|
||||||
: globalThis.location.host,
|
: globalThis.location.host,
|
||||||
tls: false,
|
tls: isURLHTTPS ? true : false,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -39,8 +41,6 @@ export const HTTP = ({ closeDialog }: TabElementProps) => {
|
|||||||
const [connectionInProgress, setConnectionInProgress] = useState(false);
|
const [connectionInProgress, setConnectionInProgress] = useState(false);
|
||||||
|
|
||||||
const onSubmit = handleSubmit(async (data) => {
|
const onSubmit = handleSubmit(async (data) => {
|
||||||
console.log(data);
|
|
||||||
|
|
||||||
setConnectionInProgress(true);
|
setConnectionInProgress(true);
|
||||||
const id = randId();
|
const id = randId();
|
||||||
const device = addDevice(id);
|
const device = addDevice(id);
|
||||||
@@ -69,8 +69,8 @@ export const HTTP = ({ closeDialog }: TabElementProps) => {
|
|||||||
<div className="flex items-center gap-2 mt-2">
|
<div className="flex items-center gap-2 mt-2">
|
||||||
<Switch
|
<Switch
|
||||||
onCheckedChange={setTLS}
|
onCheckedChange={setTLS}
|
||||||
disabled={location.protocol === "https:" || connectionInProgress}
|
disabled={isURLHTTPS || connectionInProgress}
|
||||||
checked={location.protocol === 'https:' || tlsValue}
|
checked={isURLHTTPS || tlsValue}
|
||||||
{...register("tls")}
|
{...register("tls")}
|
||||||
/>
|
/>
|
||||||
<Label>Use HTTPS</Label>
|
<Label>Use HTTPS</Label>
|
||||||
|
|||||||
Reference in New Issue
Block a user