From 89e66a923327103a977b0aa5a002c88fb5ba1898 Mon Sep 17 00:00:00 2001 From: Caleb <3040113+calebsmithdev@users.noreply.github.com> Date: Tue, 6 Jun 2023 23:34:45 -0500 Subject: [PATCH] Configurable backend port --- backend/config/__init__.py | 2 +- env.template | 1 + frontend/vite.config.js | 118 +++++++++++++++++++------------------ 3 files changed, 64 insertions(+), 57 deletions(-) diff --git a/backend/config/__init__.py b/backend/config/__init__.py index d79c50810..a72cf2b44 100644 --- a/backend/config/__init__.py +++ b/backend/config/__init__.py @@ -4,7 +4,7 @@ from dotenv import load_dotenv load_dotenv() # Uvicorn -DEV_PORT: int = 5000 +DEV_PORT: int = int(os.environ.get('VITE_BACKEND_DEV_PORT', '5000')) DEV_HOST: str = "0.0.0.0" # PATHS diff --git a/env.template b/env.template index 9fc425ff1..ee5c127f0 100644 --- a/env.template +++ b/env.template @@ -1,4 +1,5 @@ ROMM_BASE_PATH=/path/to/romm_mock +VITE_BACKEND_DEV_PORT=5000 # IGDB auth CLIENT_ID= diff --git a/frontend/vite.config.js b/frontend/vite.config.js index 2e2036745..1210aeb24 100644 --- a/frontend/vite.config.js +++ b/frontend/vite.config.js @@ -5,64 +5,70 @@ import { VitePWA } from 'vite-plugin-pwa' import pluginRewriteAll from 'vite-plugin-rewrite-all' // Utilities -import { defineConfig } from 'vite' +import { defineConfig, loadEnv } from 'vite' import { fileURLToPath, URL } from 'node:url' // https://vitejs.dev/config/ -export default defineConfig({ - plugins: [ - pluginRewriteAll(), - vue({ - template: { transformAssetUrls } - }), - vuetify({ - autoImport: true, - styles: { - configFile: 'src/styles/settings.scss', - }, - }), - VitePWA({ - manifest: { - icons: [ - { - src: "favicon.ico", - sizes: "256x256", - type: "image/ico", - purpose: "any maskable" - } - ] - } - }) - ], - define: { 'process.env': {} }, - resolve: { - alias: { - '@': fileURLToPath(new URL('./src', import.meta.url)) - }, - extensions: [ - '.js', - '.json', - '.jsx', - '.mjs', - '.ts', - '.tsx', - '.vue', +export default defineConfig(({mode}) =>{ + // Load ENV variables from the parent directory and the current directory. + const env = {...loadEnv(mode, '../'), ...loadEnv(mode, './')}; + const backendPort = env.VITE_BACKEND_DEV_PORT ?? '5000'; + + return { + plugins: [ + pluginRewriteAll(), + vue({ + template: { transformAssetUrls } + }), + vuetify({ + autoImport: true, + styles: { + configFile: 'src/styles/settings.scss', + }, + }), + VitePWA({ + manifest: { + icons: [ + { + src: "favicon.ico", + sizes: "256x256", + type: "image/ico", + purpose: "any maskable" + } + ] + } + }) ], - }, - server: { - proxy: { - '/api': { - target: 'http://localhost:5000', - changeOrigin: false, - secure: false, - rewrite: (path) => path.replace(/^\/api/, ''), - }, - '/ws': { - target: 'http://localhost:5000', - changeOrigin: false, - ws: true, - }, + define: { 'process.env': {} }, + resolve: { + alias: { + '@': fileURLToPath(new URL('./src', import.meta.url)) + }, + extensions: [ + '.js', + '.json', + '.jsx', + '.mjs', + '.ts', + '.tsx', + '.vue', + ], }, - port: 3000, - }, -}) + server: { + proxy: { + '/api': { + target: `http://localhost:${backendPort}`, + changeOrigin: false, + secure: false, + rewrite: (path) => path.replace(/^\/api/, ''), + }, + '/ws': { + target: `http://localhost:${backendPort}`, + changeOrigin: false, + ws: true, + }, + }, + port: 3000, + } + }; +}) \ No newline at end of file