Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add hostname check to decide http mode in windows #739

Merged
merged 2 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions frontend/src/components/ExternalLink.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Link } from "react-router-dom";
import { isHttpMode } from "src/utils/isHttpMode";
import { openLink } from "src/utils/openLink";

type Props = {
Expand All @@ -8,9 +9,9 @@ type Props = {
};

export default function ExternalLink({ to, className, children }: Props) {
const isHttpMode = window.location.protocol.startsWith("http");
const _isHttpMode = isHttpMode();

return isHttpMode ? (
return _isHttpMode ? (
<Link
to={to}
target="_blank"
Expand Down
12 changes: 6 additions & 6 deletions frontend/src/components/layouts/AppLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import { useInfo } from "src/hooks/useInfo";
import { useRemoveSuccessfulChannelOrder } from "src/hooks/useRemoveSuccessfulChannelOrder";
import { deleteAuthToken } from "src/lib/auth";
import { cn } from "src/lib/utils";
import { isHttpMode } from "src/utils/isHttpMode";
import { openLink } from "src/utils/openLink";
import ExternalLink from "../ExternalLink";

Expand All @@ -65,6 +66,8 @@ export default function AppLayout() {
const navigate = useNavigate();
useRemoveSuccessfulChannelOrder();

const _isHttpMode = isHttpMode();

React.useEffect(() => {
setMobileMenuOpen(false);
}, [location]);
Expand All @@ -73,15 +76,12 @@ export default function AppLayout() {
deleteAuthToken();
await refetchInfo();

const isHttpMode = window.location.protocol.startsWith("http");
if (isHttpMode) {
if (_isHttpMode) {
window.location.href = "/logout";
} else {
navigate("/", { replace: true });
}
}, [navigate, refetchInfo]);

const isHttpMode = window.location.protocol.startsWith("http");
}, [_isHttpMode, navigate, refetchInfo]);

if (!info) {
return null;
Expand Down Expand Up @@ -115,7 +115,7 @@ export default function AppLayout() {
)}
</DropdownMenuGroup>
<DropdownMenuSeparator />
{isHttpMode && (
{_isHttpMode && (
<DropdownMenuItem
onClick={logout}
className="w-full flex flex-row items-center gap-2 cursor-pointer"
Expand Down
5 changes: 3 additions & 2 deletions frontend/src/screens/BackupNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { LoadingButton } from "src/components/ui/loading-button";
import { useToast } from "src/components/ui/use-toast";

import { handleRequestError } from "src/utils/handleRequestError";
import { isHttpMode } from "src/utils/isHttpMode";
import { request } from "src/utils/request";

export function BackupNode() {
Expand All @@ -27,12 +28,12 @@ export function BackupNode() {
const onSubmitPassword = async (e: React.FormEvent) => {
e.preventDefault();

const isHttpMode = window.location.protocol.startsWith("http");
const _isHttpMode = isHttpMode();

try {
setLoading(true);

if (isHttpMode) {
if (_isHttpMode) {
const response = await fetch("/api/backup", {
method: "POST",
headers: {
Expand Down
7 changes: 4 additions & 3 deletions frontend/src/screens/setup/RestoreNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { useToast } from "src/components/ui/use-toast";

import { useInfo } from "src/hooks/useInfo";
import { handleRequestError } from "src/utils/handleRequestError";
import { isHttpMode } from "src/utils/isHttpMode";
import { request } from "src/utils/request";

export function RestoreNode() {
Expand All @@ -34,7 +35,7 @@ export function RestoreNode() {
const [loading, setLoading] = useState(false);
const [restored, setRestored] = useState(false);
const { data: info } = useInfo(restored);
const isHttpMode = window.location.protocol.startsWith("http");
const _isHttpMode = isHttpMode();

React.useEffect(() => {
if (restored && info?.setupCompleted) {
Expand Down Expand Up @@ -71,7 +72,7 @@ export function RestoreNode() {
try {
setLoading(true);

if (isHttpMode) {
if (_isHttpMode) {
const formData = new FormData();
formData.append("unlockPassword", unlockPassword);
if (file !== null) {
Expand Down Expand Up @@ -128,7 +129,7 @@ export function RestoreNode() {
placeholder="Unlock Password"
/>
</div>
{isHttpMode && (
{_isHttpMode && (
<div className="grid gap-2">
<Label htmlFor="backup">Backup File</Label>
<Input
Expand Down
6 changes: 6 additions & 0 deletions frontend/src/utils/isHttpMode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const isHttpMode = () => {
return (
window.location.protocol.startsWith("http") &&
!window.location.hostname.startsWith("wails")
);
};
Loading