mirror of
https://github.com/biersoeckli/QuickStack.git
synced 2026-01-02 01:30:38 -06:00
fix HostnameCheck
This commit is contained in:
@@ -1,11 +1,10 @@
|
||||
import ProjectPage from "./projects/project-page";
|
||||
import paramService, { ParamService } from "@/server/services/param.service";
|
||||
import HostnameCheck from "../components/custom/hostname-check";
|
||||
import HostnameCheck from "./settings/server/hostname-check";
|
||||
|
||||
export default async function Home() {
|
||||
const configuredDomain = await paramService.getString(ParamService.QS_SERVER_HOSTNAME);
|
||||
return <>
|
||||
<ProjectPage />
|
||||
<HostnameCheck serverParamHostname={configuredDomain} />
|
||||
<HostnameCheck />
|
||||
</>;
|
||||
}
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
'use server'
|
||||
|
||||
import { getAuthUserSession, saveFormAction } from "@/server/utils/action-wrapper.utils";
|
||||
import { getAuthUserSession, saveFormAction, simpleAction } from "@/server/utils/action-wrapper.utils";
|
||||
import paramService, { ParamService } from "@/server/services/param.service";
|
||||
import { QsIngressSettingsModel, qsIngressSettingsZodModel } from "@/model/qs-settings.model";
|
||||
import { QsLetsEncryptSettingsModel, qsLetsEncryptSettingsZodModel } from "@/model/qs-letsencrypt-settings.model";
|
||||
import quickStackService from "@/server/services/qs.service";
|
||||
import { ServerActionResult } from "@/model/server-action-error-return.model";
|
||||
|
||||
export const updateIngressSettings = async (prevState: any, inputData: QsIngressSettingsModel) =>
|
||||
saveFormAction(inputData, qsIngressSettingsZodModel, async (validatedData) => {
|
||||
@@ -39,3 +40,10 @@ export const updateLetsEncryptSettings = async (prevState: any, inputData: QsLet
|
||||
|
||||
await quickStackService.createOrUpdateCertIssuer(validatedData.letsEncryptMail);
|
||||
});
|
||||
|
||||
export const getConfiguredHostname: () => Promise<ServerActionResult<unknown, string | undefined>> = async () =>
|
||||
simpleAction(async () => {
|
||||
await getAuthUserSession();
|
||||
|
||||
return await paramService.getString(ParamService.QS_SERVER_HOSTNAME);
|
||||
});
|
||||
|
||||
34
src/app/settings/server/hostname-check.tsx
Normal file
34
src/app/settings/server/hostname-check.tsx
Normal file
@@ -0,0 +1,34 @@
|
||||
'use client'
|
||||
|
||||
import { toast } from "sonner";
|
||||
import { useEffect } from "react";
|
||||
import { getConfiguredHostname } from "./actions";
|
||||
import { ExternalLink, Link } from "lucide-react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
|
||||
export default function HostnameCheck() {
|
||||
|
||||
const checkForCorrectHostname = async () => {
|
||||
const configuredDomain = await getConfiguredHostname();
|
||||
if (configuredDomain.status === 'success') {
|
||||
const hostname = window.location.hostname;
|
||||
const serverParamHostname = configuredDomain.data;
|
||||
if (serverParamHostname && serverParamHostname !== hostname) {
|
||||
toast.warning(`QuickStack is configured to run on a different domain. Please open the application on https://${serverParamHostname}`, {
|
||||
duration: 10000,
|
||||
action: {
|
||||
label: <Button variant="ghost"><ExternalLink /> open</Button>,
|
||||
onClick: () => {
|
||||
window.open(`https://${serverParamHostname}`, '_blank');
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
checkForCorrectHostname();
|
||||
});
|
||||
return <></>;
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
'use client'
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
import ProjectPage from "../../app/projects/project-page";
|
||||
import paramService, { ParamService } from "@/server/services/param.service";
|
||||
import { cookies } from "next/headers";
|
||||
import { toast } from "sonner";
|
||||
import { usePathname } from "next/navigation";
|
||||
import { useRouter } from "next/router";
|
||||
import { useEffect } from "react";
|
||||
|
||||
export default function HostnameCheck({ serverParamHostname }: { serverParamHostname?: string }) {
|
||||
useEffect(() => {
|
||||
const hostname = window.location.hostname;
|
||||
if (serverParamHostname && serverParamHostname !== hostname) {
|
||||
toast.warning(`QuickStack is configured to run on a different domain. Please open the application on https://${serverParamHostname}`, {
|
||||
duration: 10000,
|
||||
action: {
|
||||
label: 'Open',
|
||||
onClick: () => {
|
||||
window.location.href = `https://${serverParamHostname}`;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}, [serverParamHostname]);
|
||||
return <></>;
|
||||
}
|
||||
Reference in New Issue
Block a user