From 3901ef0e21a1a8bf46918a2cc6eb572a6bf95b4d Mon Sep 17 00:00:00 2001 From: PamplemomM <183356185+PamplemomM@users.noreply.github.com> Date: Tue, 25 Nov 2025 19:09:58 +0100 Subject: [PATCH 1/4] [+] - Base URL env variable handling Handling of the env variable QSTH_BASE_URL. This env variable must allow you tu run the app on custom subpages. (ex: myapp.com/questhelper) --- src/App.tsx | 2 +- vite.config.ts | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 4d4a9bd..93143ce 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -11,7 +11,7 @@ const App = () => ( - + } /> {/* custom routes here "*" for all */} diff --git a/vite.config.ts b/vite.config.ts index 9d6ef54..08a84bb 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -3,14 +3,20 @@ import react from '@vitejs/plugin-react-swc'; import path from 'path'; export default defineConfig(({ mode }) => { - const env = loadEnv(mode, process.cwd(), ['QUESTHELPER_HOST', 'QUESTHELPER_PORT']); + const env = loadEnv(mode, process.cwd(), ['QUESTHELPER_HOST', 'QUESTHELPER_PORT', 'QSTH_BASE_URL']); const getPort = () => { const p = env.QUESTHELPER_PORT ?? process.env.QUESTHELPER_PORT; return p ? parseInt(p, 10) : 8082; }; + const getBase = () => { + const b = env.QSTH_BASE_URL ?? process.env.QSTH_BASE_URL ?? '/'; + return b.endsWith('/') ? b : b + '/'; + }; + return { + base: getBase(), plugins: [react()], resolve: { alias: { From ee2ba1517bd82eb98475172f8645ea21e016140a Mon Sep 17 00:00:00 2001 From: PamplemomM <183356185+PamplemomM@users.noreply.github.com> Date: Tue, 25 Nov 2025 19:25:03 +0100 Subject: [PATCH 2/4] [+] - Allowed host management You can now manage the allowed host with the environment variable QSTH_ALLOWED_HOST --- vite.config.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/vite.config.ts b/vite.config.ts index 08a84bb..60a9131 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -3,7 +3,7 @@ import react from '@vitejs/plugin-react-swc'; import path from 'path'; export default defineConfig(({ mode }) => { - const env = loadEnv(mode, process.cwd(), ['QUESTHELPER_HOST', 'QUESTHELPER_PORT', 'QSTH_BASE_URL']); + const env = loadEnv(mode, process.cwd(), ['QUESTHELPER_HOST', 'QUESTHELPER_PORT', 'QSTH_BASE_URL', 'QSTH_ALLOWED_HOSTS']); const getPort = () => { const p = env.QUESTHELPER_PORT ?? process.env.QUESTHELPER_PORT; @@ -15,6 +15,11 @@ export default defineConfig(({ mode }) => { return b.endsWith('/') ? b : b + '/'; }; + const getAllowedHosts = () => { + const hosts = env.QSTH_ALLOWED_HOSTS ?? process.env.QSTH_ALLOWED_HOSTS ?? '*'; + return hosts === '*' ? true : hosts.split(',').map(h => h.trim()); + }; + return { base: getBase(), plugins: [react()], @@ -27,6 +32,8 @@ export default defineConfig(({ mode }) => { host: env.QUESTHELPER_HOST ?? process.env.QUESTHELPER_HOST ?? '::', port: getPort(), strictPort: true, + middlewareMode: false, + cors: getAllowedHosts(), }, envPrefix: 'QSTH_', }; From 1f21575a461b84f09cbb0f621c7e9b06f7f64825 Mon Sep 17 00:00:00 2001 From: PamplemomM <183356185+PamplemomM@users.noreply.github.com> Date: Tue, 25 Nov 2025 19:31:37 +0100 Subject: [PATCH 3/4] [!] - Fixed Allowed Host Hosting on custom subdomain would not worked. The browser would have search in '/' instead of '/QSTH_BASE_URL' because the host wasn't allowed --- src/App.tsx | 2 +- vite.config.ts | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 93143ce..7b61855 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -11,7 +11,7 @@ const App = () => ( - + } /> {/* custom routes here "*" for all */} diff --git a/vite.config.ts b/vite.config.ts index 60a9131..2ad7a66 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -31,9 +31,7 @@ export default defineConfig(({ mode }) => { server: { host: env.QUESTHELPER_HOST ?? process.env.QUESTHELPER_HOST ?? '::', port: getPort(), - strictPort: true, - middlewareMode: false, - cors: getAllowedHosts(), + allowedHosts: getAllowedHosts(), }, envPrefix: 'QSTH_', }; From 7cfc7f3f2debf758382e034833be22eeb4175af2 Mon Sep 17 00:00:00 2001 From: PamplemomM <183356185+PamplemomM@users.noreply.github.com> Date: Tue, 25 Nov 2025 19:37:14 +0100 Subject: [PATCH 4/4] [~] - Updated README.md Updated documentation about new environment variables. --- README.md | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index e2fbfb6..6538784 100644 --- a/README.md +++ b/README.md @@ -58,16 +58,19 @@ This will start the QuestHelper server, which you can access at [http://localhos You can customize settings using environment variables: | Variable | Purpose | Default Value | -|----------|---------|---------| +|----------|---------|---------------| | `QSTH_HOST` | Set the host address | `::` | | `QSTH_PORT` | Set the port number | `8082` | +| `QSTH_ALLOWED_HOST` | Controls allowed hosts (`true` to accept any host) | `true` | +| `QSTH_BASE_URL` | Subfolder name when hosting under a subpath (ex: use `app` for site.com/app). Leave empty for root. | `''` | -**Example:** +Example: ```bash -QUESTHELPER_HOST='0.0.0.0' QUESTHELPER_PORT=3000 npm run app +# bind to all interfaces on port 3000, allow any host, and serve under /questhelper +QSTH_HOST='0.0.0.0' QSTH_PORT=3000 QSTH_ALLOWED_HOST='true' QSTH_BASE_URL='questhelper' npm run app ``` -Since the app only uses the root `/` path, you can safely use a custom domain or reverse proxy without conflicts. +Since the app normally uses the root (`/`) path, you can safely use a custom domain or reverse proxy without conflicts. If you set `QSTH_BASE_URL`, ensure your reverse proxy forwards the subpath (and rewrites requests) to the app accordingly. ## 💬 Support