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({
origin: "*",
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({
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" }));

View File

@@ -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",

View File

@@ -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());

View File

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

View File

@@ -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;
}
}
// SSH Host Management API (port 8081)
export let sshHostApi = createApiInstance(getApiUrl("/ssh", 8081), "SSH_HOST");
// Initialize API instances
function initializeApiInstances() {
// SSH Host Management API (port 8081)
sshHostApi = createApiInstance(getApiUrl("/ssh", 8081), "SSH_HOST");
// Tunnel Management API (port 8083)
export let tunnelApi = createApiInstance(getApiUrl("/ssh", 8083), "TUNNEL");
// Tunnel Management API (port 8083)
tunnelApi = createApiInstance(getApiUrl("/ssh", 8083), "TUNNEL");
// File Manager Operations API (port 8084)
export let fileManagerApi = createApiInstance(
// 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)
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 = createApiInstance(getApiUrl("", 8085), "STATS");
export let statsApi: AxiosInstance;
// Authentication API (port 8081)
export let authApi = createApiInstance(getApiUrl("", 8081), "AUTH");
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;