From 6f2901b08cd0d976849560b0a0a7fdc8c955d63e Mon Sep 17 00:00:00 2001 From: Gronod Date: Thu, 28 May 2026 08:03:29 +0100 Subject: [PATCH] fix: resolve frontend connection issues by introducing concurrent startup and dynamic proxy configuration --- client/vite.config.js | 60 ++++++++++++++++++++++++++----------------- package.json | 4 ++- 2 files changed, 39 insertions(+), 25 deletions(-) diff --git a/client/vite.config.js b/client/vite.config.js index d42a573..8b38bce 100644 --- a/client/vite.config.js +++ b/client/vite.config.js @@ -1,28 +1,40 @@ // Copyright (c) 2026 Gordon Bolton. MIT License. -import { defineConfig } from 'vite' +import { defineConfig, loadEnv } from 'vite' +import path from 'path' -export default defineConfig({ - build: { - outDir: '../public', - emptyOutDir: false, - rollupOptions: { - input: { - main: './src/main.js' - }, - output: { - entryFileNames: 'app.js', - chunkFileNames: '[name].js', - assetFileNames: '[name][extname]' +export default defineConfig(({ mode }) => { + // Load env variables from root directory to match backend TLS configuration + const env = loadEnv(mode, path.resolve(__dirname, '..'), ''); + + const port = env.PORT || 3001; + const tlsEnabled = (env.TLS_ENABLED || 'true').toLowerCase() !== 'false'; + const target = `${tlsEnabled ? 'https' : 'http'}://localhost:${port}`; + + return { + build: { + outDir: '../public', + emptyOutDir: false, + rollupOptions: { + input: { + main: './src/main.js' + }, + output: { + entryFileNames: 'app.js', + chunkFileNames: '[name].js', + assetFileNames: '[name][extname]' + } + } + }, + server: { + port: 5173, + host: true, // Listen on all network interfaces + proxy: { + '/api': { + target: target, + changeOrigin: true, + secure: false // Allow self-signed certificate in development + } } } - }, - server: { - port: 5173, - proxy: { - '/api': { - target: 'http://localhost:3001', - changeOrigin: true - } - } - } -}) + }; +}); diff --git a/package.json b/package.json index 39b0fb7..74936aa 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,9 @@ "description": "A personal media download dashboard that shows your downloads 'so far' while you relax on the sofa waiting for your *arr services to finish", "main": "server/index.js", "scripts": { - "dev": "nodemon server/index.js", + "dev:server": "nodemon server/index.js", + "dev:client": "npm run dev --prefix client", + "dev": "concurrently -n 'server,client' -c 'blue,green' 'npm run dev:server' 'npm run dev:client'", "start": "node server/index.js", "install:all": "npm install", "test": "vitest run",