fix: evitar URLs localhost em builds de produção
This commit is contained in:
parent
a1937c7515
commit
619f311daa
1 changed files with 25 additions and 2 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
import { useEffect, useState } from "react"
|
import { useEffect, useMemo, useState } from "react"
|
||||||
import { createRoot } from "react-dom/client"
|
import { createRoot } from "react-dom/client"
|
||||||
import { invoke } from "@tauri-apps/api/core"
|
import { invoke } from "@tauri-apps/api/core"
|
||||||
import { Store } from "@tauri-apps/plugin-store"
|
import { Store } from "@tauri-apps/plugin-store"
|
||||||
|
|
@ -149,6 +149,29 @@ function App() {
|
||||||
})()
|
})()
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!store || !config) return
|
||||||
|
const normalizedAppUrl = normalizeUrl(config.appUrl, appUrl)
|
||||||
|
const normalizedApiUrl = normalizeUrl(config.apiBaseUrl, apiBaseUrl)
|
||||||
|
const shouldForceRemote = import.meta.env.MODE === "production"
|
||||||
|
const nextAppUrl = shouldForceRemote && normalizedAppUrl.includes("localhost") ? appUrl : normalizedAppUrl
|
||||||
|
const nextApiUrl = shouldForceRemote && normalizedApiUrl.includes("localhost") ? apiBaseUrl : normalizedApiUrl
|
||||||
|
if (nextAppUrl !== config.appUrl || nextApiUrl !== config.apiBaseUrl) {
|
||||||
|
const updatedConfig = { ...config, appUrl: nextAppUrl, apiBaseUrl: nextApiUrl }
|
||||||
|
setConfig(updatedConfig)
|
||||||
|
writeConfig(store, updatedConfig).catch((err) => console.error("Falha ao atualizar configuração", err))
|
||||||
|
}
|
||||||
|
}, [store, config])
|
||||||
|
|
||||||
|
const resolvedAppUrl = useMemo(() => {
|
||||||
|
if (!config?.appUrl) return appUrl
|
||||||
|
const normalized = normalizeUrl(config.appUrl, appUrl)
|
||||||
|
if (import.meta.env.MODE === "production" && normalized.includes("localhost")) {
|
||||||
|
return appUrl
|
||||||
|
}
|
||||||
|
return normalized
|
||||||
|
}, [config?.appUrl, appUrl])
|
||||||
|
|
||||||
async function register() {
|
async function register() {
|
||||||
if (!profile) return
|
if (!profile) return
|
||||||
if (!provisioningSecret.trim()) { setError("Informe o código de provisionamento."); return }
|
if (!provisioningSecret.trim()) { setError("Informe o código de provisionamento."); return }
|
||||||
|
|
@ -197,7 +220,7 @@ function App() {
|
||||||
|
|
||||||
async function openSystem() {
|
async function openSystem() {
|
||||||
if (!token || !config) return
|
if (!token || !config) return
|
||||||
const url = `${config.appUrl}/machines/handshake?token=${encodeURIComponent(token)}`
|
const url = `${resolvedAppUrl}/machines/handshake?token=${encodeURIComponent(token)}`
|
||||||
try {
|
try {
|
||||||
// open in default browser; fallback to in-webview
|
// open in default browser; fallback to in-webview
|
||||||
const { openUrl } = await import("@tauri-apps/plugin-opener")
|
const { openUrl } = await import("@tauri-apps/plugin-opener")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue