fix: no auto-redirect on public domain after tunnel setup, show next button instead
This commit is contained in:
@@ -29,20 +29,7 @@ export default function GetPublicDomain() {
|
|||||||
const currentVersion = useAppSelector((store) => store.server.version, shallowEqual);
|
const currentVersion = useAppSelector((store) => store.server.version, shallowEqual);
|
||||||
const { data: autoInfo } = useGetAutoTunnelInfoQuery();
|
const { data: autoInfo } = useGetAutoTunnelInfoQuery();
|
||||||
|
|
||||||
// If already on the tunnel domain, skip this step
|
const isLocalhost = /^https?:\/\/(localhost|127\.0\.0\.1)(:\d+)?$/.test(location.origin);
|
||||||
useEffect(() => {
|
|
||||||
const tunnelUrl = autoInfo?.tunnel_status?.url;
|
|
||||||
if (tunnelUrl) {
|
|
||||||
try {
|
|
||||||
const tunnelOrigin = new URL(tunnelUrl).origin;
|
|
||||||
if (location.origin === tunnelOrigin) {
|
|
||||||
nextStep();
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
// ignore malformed URL
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, [autoInfo]);
|
|
||||||
|
|
||||||
const [phase, setPhase] = useState<Phase>("prompt");
|
const [phase, setPhase] = useState<Phase>("prompt");
|
||||||
const [logs, setLogs] = useState<string[]>([]);
|
const [logs, setLogs] = useState<string[]>([]);
|
||||||
@@ -65,6 +52,7 @@ export default function GetPublicDomain() {
|
|||||||
function startCountdown(url: string) {
|
function startCountdown(url: string) {
|
||||||
setTunnelUrl(url);
|
setTunnelUrl(url);
|
||||||
setPhase("done");
|
setPhase("done");
|
||||||
|
if (!isLocalhost) return;
|
||||||
let remaining = COUNTDOWN_SECONDS;
|
let remaining = COUNTDOWN_SECONDS;
|
||||||
setCountdown(remaining);
|
setCountdown(remaining);
|
||||||
countRef.current = setInterval(() => {
|
countRef.current = setInterval(() => {
|
||||||
@@ -211,9 +199,25 @@ export default function GetPublicDomain() {
|
|||||||
<span className="font-mono text-sm break-all text-green-600 dark:text-green-400">
|
<span className="font-mono text-sm break-all text-green-600 dark:text-green-400">
|
||||||
{tunnelUrl}
|
{tunnelUrl}
|
||||||
</span>
|
</span>
|
||||||
<span className="text-lg font-semibold">
|
{isLocalhost ? (
|
||||||
{t("tunnel_redirect_countdown", { seconds: countdown })}
|
<span className="text-lg font-semibold">
|
||||||
</span>
|
{t("tunnel_redirect_countdown", { seconds: countdown })}
|
||||||
|
</span>
|
||||||
|
) : (
|
||||||
|
<div className="flex flex-col items-center gap-3">
|
||||||
|
<a
|
||||||
|
href={tunnelUrl}
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
className="text-blue-500 underline text-sm"
|
||||||
|
>
|
||||||
|
{tunnelUrl}
|
||||||
|
</a>
|
||||||
|
<StyledButton className="w-32 h-11" onClick={nextStep}>
|
||||||
|
{t("tunnel_opt_in_skip")}
|
||||||
|
</StyledButton>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user