v1.6.0 #221
@@ -16,7 +16,7 @@ app.use(
|
||||
cors({
|
||||
origin: "*",
|
||||
methods: ["GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"],
|
||||
allowedHeaders: ["Content-Type", "Authorization"],
|
||||
allowedHeaders: ["Content-Type", "Authorization", "User-Agent", "X-Electron-App"],
|
||||
}),
|
||||
);
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ app.use(
|
||||
cors({
|
||||
origin: "*",
|
||||
methods: ["GET", "POST", "PUT", "DELETE", "OPTIONS"],
|
||||
allowedHeaders: ["Content-Type", "Authorization"],
|
||||
allowedHeaders: ["Content-Type", "Authorization", "User-Agent", "X-Electron-App"],
|
||||
}),
|
||||
);
|
||||
app.use(express.json({ limit: "100mb" }));
|
||||
|
||||
@@ -277,12 +277,12 @@ app.use(
|
||||
cors({
|
||||
origin: "*",
|
||||
methods: ["GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"],
|
||||
allowedHeaders: ["Content-Type", "Authorization"],
|
||||
allowedHeaders: ["Content-Type", "Authorization", "User-Agent", "X-Electron-App"],
|
||||
}),
|
||||
);
|
||||
app.use((req, res, next) => {
|
||||
res.header("Access-Control-Allow-Origin", "*");
|
||||
res.header("Access-Control-Allow-Headers", "Content-Type, Authorization");
|
||||
res.header("Access-Control-Allow-Headers", "Content-Type, Authorization, User-Agent, X-Electron-App");
|
||||
res.header(
|
||||
"Access-Control-Allow-Methods",
|
||||
"GET, POST, PUT, PATCH, DELETE, OPTIONS",
|
||||
|
||||
@@ -21,7 +21,7 @@ app.use(
|
||||
cors({
|
||||
origin: "*",
|
||||
methods: ["GET", "POST", "PUT", "DELETE", "OPTIONS"],
|
||||
allowedHeaders: "Origin,X-Requested-With,Content-Type,Accept,Authorization",
|
||||
allowedHeaders: ["Origin", "X-Requested-With", "Content-Type", "Accept", "Authorization", "User-Agent", "X-Electron-App"],
|
||||
}),
|
||||
);
|
||||
app.use(express.json());
|
||||
|
||||
@@ -656,7 +656,6 @@ export function HomepageAuth({
|
||||
|
||||
{resetStep === "verify" && (
|
||||
<>
|
||||
o
|
||||
<div className="text-center text-muted-foreground mb-4">
|
||||
<p>
|
||||
{t("auth.enterResetCode")}{" "}
|
||||
|
||||
@@ -173,7 +173,7 @@ function createApiInstance(
|
||||
);
|
||||
}
|
||||
|
||||
if (isElectron) {
|
||||
if (isElectron()) {
|
||||
config.headers["X-Electron-App"] = "true";
|
||||
config.headers["User-Agent"] = "Termix-Electron/1.6.0";
|
||||
}
|
||||
@@ -289,17 +289,22 @@ function createApiInstance(
|
||||
// API INSTANCES
|
||||
// ============================================================================
|
||||
|
||||
const isDev =
|
||||
function isDev(): boolean {
|
||||
return (
|
||||
process.env.NODE_ENV === "development" &&
|
||||
(window.location.port === "3000" ||
|
||||
window.location.port === "5173" ||
|
||||
window.location.port === "");
|
||||
window.location.port === "" ||
|
||||
window.location.hostname === "localhost" ||
|
||||
window.location.hostname === "127.0.0.1")
|
||||
);
|
||||
}
|
||||
|
||||
let apiHost = import.meta.env.VITE_API_HOST || "localhost";
|
||||
let apiPort = 8081;
|
||||
let configuredServerUrl: string | null = null;
|
||||
|
||||
if (isElectron) {
|
||||
if (isElectron()) {
|
||||
apiPort = 8081;
|
||||
}
|
||||
|
||||
@@ -309,7 +314,7 @@ export interface ServerConfig {
|
||||
}
|
||||
|
||||
export async function getServerConfig(): Promise<ServerConfig | null> {
|
||||
if (!isElectron) return null;
|
||||
if (!isElectron()) return null;
|
||||
|
||||
try {
|
||||
const result = await (window as any).electronAPI?.invoke(
|
||||
@@ -323,7 +328,7 @@ export async function getServerConfig(): Promise<ServerConfig | null> {
|
||||
}
|
||||
|
||||
export async function saveServerConfig(config: ServerConfig): Promise<boolean> {
|
||||
if (!isElectron) return false;
|
||||
if (!isElectron()) return false;
|
||||
|
||||
try {
|
||||
const result = await (window as any).electronAPI?.invoke(
|
||||
@@ -345,7 +350,7 @@ export async function saveServerConfig(config: ServerConfig): Promise<boolean> {
|
||||
export async function testServerConnection(
|
||||
serverUrl: string,
|
||||
): Promise<{ success: boolean; error?: string }> {
|
||||
if (!isElectron)
|
||||
if (!isElectron())
|
||||
return { success: false, error: "Not in Electron environment" };
|
||||
|
||||
try {
|
||||
@@ -360,7 +365,7 @@ export async function testServerConnection(
|
||||
}
|
||||
}
|
||||
|
||||
if (isElectron) {
|
||||
if (isElectron()) {
|
||||
getServerConfig().then((config) => {
|
||||
if (config?.serverUrl) {
|
||||
configuredServerUrl = config.serverUrl;
|
||||
@@ -370,36 +375,57 @@ if (isElectron) {
|
||||
}
|
||||
|
||||
function getApiUrl(path: string, defaultPort: number): string {
|
||||
if (isElectron()) {
|
||||
if (isDev()) {
|
||||
return `http://${apiHost}:${defaultPort}${path}`;
|
||||
} else if (isElectron()) {
|
||||
if (configuredServerUrl) {
|
||||
const baseUrl = configuredServerUrl.replace(/\/$/, "");
|
||||
return `${baseUrl}${path}`;
|
||||
}
|
||||
return "http://no-server-configured";
|
||||
} else if (isDev) {
|
||||
return `http://${apiHost}:${defaultPort}${path}`;
|
||||
} else {
|
||||
return path;
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize API instances
|
||||
function initializeApiInstances() {
|
||||
// SSH Host Management API (port 8081)
|
||||
export let sshHostApi = createApiInstance(getApiUrl("/ssh", 8081), "SSH_HOST");
|
||||
sshHostApi = createApiInstance(getApiUrl("/ssh", 8081), "SSH_HOST");
|
||||
|
||||
// Tunnel Management API (port 8083)
|
||||
export let tunnelApi = createApiInstance(getApiUrl("/ssh", 8083), "TUNNEL");
|
||||
tunnelApi = createApiInstance(getApiUrl("/ssh", 8083), "TUNNEL");
|
||||
|
||||
// File Manager Operations API (port 8084)
|
||||
export let fileManagerApi = createApiInstance(
|
||||
fileManagerApi = createApiInstance(
|
||||
getApiUrl("/ssh/file_manager", 8084),
|
||||
"FILE_MANAGER",
|
||||
);
|
||||
|
||||
// Server Statistics API (port 8085)
|
||||
export let statsApi = createApiInstance(getApiUrl("", 8085), "STATS");
|
||||
statsApi = createApiInstance(getApiUrl("", 8085), "STATS");
|
||||
|
||||
// Authentication API (port 8081)
|
||||
export let authApi = createApiInstance(getApiUrl("", 8081), "AUTH");
|
||||
authApi = createApiInstance(getApiUrl("", 8081), "AUTH");
|
||||
}
|
||||
|
||||
// SSH Host Management API (port 8081)
|
||||
export let sshHostApi: AxiosInstance;
|
||||
|
||||
// Tunnel Management API (port 8083)
|
||||
export let tunnelApi: AxiosInstance;
|
||||
|
||||
// File Manager Operations API (port 8084)
|
||||
export let fileManagerApi: AxiosInstance;
|
||||
|
||||
// Server Statistics API (port 8085)
|
||||
export let statsApi: AxiosInstance;
|
||||
|
||||
// Authentication API (port 8081)
|
||||
export let authApi: AxiosInstance;
|
||||
|
||||
// Initialize API instances immediately
|
||||
initializeApiInstances();
|
||||
|
||||
function updateApiInstances() {
|
||||
systemLogger.info("Updating API instances with new server configuration", {
|
||||
@@ -407,14 +433,7 @@ function updateApiInstances() {
|
||||
configuredServerUrl,
|
||||
});
|
||||
|
||||
sshHostApi = createApiInstance(getApiUrl("/ssh", 8081), "SSH_HOST");
|
||||
tunnelApi = createApiInstance(getApiUrl("/ssh", 8083), "TUNNEL");
|
||||
fileManagerApi = createApiInstance(
|
||||
getApiUrl("/ssh/file_manager", 8084),
|
||||
"FILE_MANAGER",
|
||||
);
|
||||
statsApi = createApiInstance(getApiUrl("", 8085), "STATS");
|
||||
authApi = createApiInstance(getApiUrl("", 8081), "AUTH");
|
||||
initializeApiInstances();
|
||||
|
||||
// Make configuredServerUrl available globally for components that need it
|
||||
(window as any).configuredServerUrl = configuredServerUrl;
|
||||
|
||||
Reference in New Issue
Block a user