v1.6.0 #221

Merged
LukeGus merged 74 commits from dev-1.6.0 into main 2025-09-12 19:42:00 +00:00
6 changed files with 54 additions and 36 deletions
Showing only changes of commit 2347d4bd2f - Show all commits

View File

@@ -16,7 +16,7 @@ app.use(
cors({ cors({
origin: "*", origin: "*",
methods: ["GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"], methods: ["GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"],
allowedHeaders: ["Content-Type", "Authorization"], allowedHeaders: ["Content-Type", "Authorization", "User-Agent", "X-Electron-App"],
}), }),
); );

View File

@@ -12,7 +12,7 @@ app.use(
cors({ cors({
origin: "*", origin: "*",
methods: ["GET", "POST", "PUT", "DELETE", "OPTIONS"], 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" })); app.use(express.json({ limit: "100mb" }));

View File

@@ -277,12 +277,12 @@ app.use(
cors({ cors({
origin: "*", origin: "*",
methods: ["GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"], 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) => { app.use((req, res, next) => {
res.header("Access-Control-Allow-Origin", "*"); 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( res.header(
"Access-Control-Allow-Methods", "Access-Control-Allow-Methods",
"GET, POST, PUT, PATCH, DELETE, OPTIONS", "GET, POST, PUT, PATCH, DELETE, OPTIONS",

View File

@@ -21,7 +21,7 @@ app.use(
cors({ cors({
origin: "*", origin: "*",
methods: ["GET", "POST", "PUT", "DELETE", "OPTIONS"], 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()); app.use(express.json());

View File

@@ -656,7 +656,6 @@ export function HomepageAuth({
{resetStep === "verify" && ( {resetStep === "verify" && (
<> <>
o
<div className="text-center text-muted-foreground mb-4"> <div className="text-center text-muted-foreground mb-4">
<p> <p>
{t("auth.enterResetCode")}{" "} {t("auth.enterResetCode")}{" "}

View File

@@ -173,7 +173,7 @@ function createApiInstance(
); );
} }
if (isElectron) { if (isElectron()) {
config.headers["X-Electron-App"] = "true"; config.headers["X-Electron-App"] = "true";
config.headers["User-Agent"] = "Termix-Electron/1.6.0"; config.headers["User-Agent"] = "Termix-Electron/1.6.0";
} }
@@ -289,17 +289,22 @@ function createApiInstance(
// API INSTANCES // API INSTANCES
// ============================================================================ // ============================================================================
const isDev = function isDev(): boolean {
process.env.NODE_ENV === "development" && return (
(window.location.port === "3000" || process.env.NODE_ENV === "development" &&
window.location.port === "5173" || (window.location.port === "3000" ||
window.location.port === ""); window.location.port === "5173" ||
window.location.port === "" ||
window.location.hostname === "localhost" ||
window.location.hostname === "127.0.0.1")
);
}
let apiHost = import.meta.env.VITE_API_HOST || "localhost"; let apiHost = import.meta.env.VITE_API_HOST || "localhost";
let apiPort = 8081; let apiPort = 8081;
let configuredServerUrl: string | null = null; let configuredServerUrl: string | null = null;
if (isElectron) { if (isElectron()) {
apiPort = 8081; apiPort = 8081;
} }
@@ -309,7 +314,7 @@ export interface ServerConfig {
} }
export async function getServerConfig(): Promise<ServerConfig | null> { export async function getServerConfig(): Promise<ServerConfig | null> {
if (!isElectron) return null; if (!isElectron()) return null;
try { try {
const result = await (window as any).electronAPI?.invoke( 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> { export async function saveServerConfig(config: ServerConfig): Promise<boolean> {
if (!isElectron) return false; if (!isElectron()) return false;
try { try {
const result = await (window as any).electronAPI?.invoke( const result = await (window as any).electronAPI?.invoke(
@@ -345,7 +350,7 @@ export async function saveServerConfig(config: ServerConfig): Promise<boolean> {
export async function testServerConnection( export async function testServerConnection(
serverUrl: string, serverUrl: string,
): Promise<{ success: boolean; error?: string }> { ): Promise<{ success: boolean; error?: string }> {
if (!isElectron) if (!isElectron())
return { success: false, error: "Not in Electron environment" }; return { success: false, error: "Not in Electron environment" };
try { try {
@@ -360,7 +365,7 @@ export async function testServerConnection(
} }
} }
if (isElectron) { if (isElectron()) {
getServerConfig().then((config) => { getServerConfig().then((config) => {
if (config?.serverUrl) { if (config?.serverUrl) {
configuredServerUrl = config.serverUrl; configuredServerUrl = config.serverUrl;
@@ -370,36 +375,57 @@ if (isElectron) {
} }
function getApiUrl(path: string, defaultPort: number): string { function getApiUrl(path: string, defaultPort: number): string {
if (isElectron()) { if (isDev()) {
return `http://${apiHost}:${defaultPort}${path}`;
} else if (isElectron()) {
if (configuredServerUrl) { if (configuredServerUrl) {
const baseUrl = configuredServerUrl.replace(/\/$/, ""); const baseUrl = configuredServerUrl.replace(/\/$/, "");
return `${baseUrl}${path}`; return `${baseUrl}${path}`;
} }
return "http://no-server-configured"; return "http://no-server-configured";
} else if (isDev) {
return `http://${apiHost}:${defaultPort}${path}`;
} else { } else {
return path; return path;
} }
} }
// Initialize API instances
function initializeApiInstances() {
// SSH Host Management API (port 8081)
sshHostApi = createApiInstance(getApiUrl("/ssh", 8081), "SSH_HOST");
// Tunnel Management API (port 8083)
tunnelApi = createApiInstance(getApiUrl("/ssh", 8083), "TUNNEL");
// File Manager Operations API (port 8084)
fileManagerApi = createApiInstance(
getApiUrl("/ssh/file_manager", 8084),
"FILE_MANAGER",
);
// Server Statistics API (port 8085)
statsApi = createApiInstance(getApiUrl("", 8085), "STATS");
// Authentication API (port 8081)
authApi = createApiInstance(getApiUrl("", 8081), "AUTH");
}
// SSH Host Management API (port 8081) // SSH Host Management API (port 8081)
export let sshHostApi = createApiInstance(getApiUrl("/ssh", 8081), "SSH_HOST"); export let sshHostApi: AxiosInstance;
// Tunnel Management API (port 8083) // Tunnel Management API (port 8083)
export let tunnelApi = createApiInstance(getApiUrl("/ssh", 8083), "TUNNEL"); export let tunnelApi: AxiosInstance;
// File Manager Operations API (port 8084) // File Manager Operations API (port 8084)
export let fileManagerApi = createApiInstance( export let fileManagerApi: AxiosInstance;
getApiUrl("/ssh/file_manager", 8084),
"FILE_MANAGER",
);
// Server Statistics API (port 8085) // Server Statistics API (port 8085)
export let statsApi = createApiInstance(getApiUrl("", 8085), "STATS"); export let statsApi: AxiosInstance;
// Authentication API (port 8081) // Authentication API (port 8081)
export let authApi = createApiInstance(getApiUrl("", 8081), "AUTH"); export let authApi: AxiosInstance;
// Initialize API instances immediately
initializeApiInstances();
function updateApiInstances() { function updateApiInstances() {
systemLogger.info("Updating API instances with new server configuration", { systemLogger.info("Updating API instances with new server configuration", {
@@ -407,14 +433,7 @@ function updateApiInstances() {
configuredServerUrl, configuredServerUrl,
}); });
sshHostApi = createApiInstance(getApiUrl("/ssh", 8081), "SSH_HOST"); initializeApiInstances();
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");
// Make configuredServerUrl available globally for components that need it // Make configuredServerUrl available globally for components that need it
(window as any).configuredServerUrl = configuredServerUrl; (window as any).configuredServerUrl = configuredServerUrl;