Browse Source

Merge pull request #482 from danditomaso/issue-481-node-connecting-on-https

fix: update TLS setting if URL is using HTTPS

Fixes #481
pull/483/head
Dan Ditomaso 1 year ago
committed by GitHub
parent
commit
39f26f475b
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 12
      src/components/PageComponents/Connect/HTTP.tsx

12
src/components/PageComponents/Connect/HTTP.tsx

@ -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>

Loading…
Cancel
Save