Parametrize configurations¡

This commit is contained in:
2025-12-24 12:44:34 +01:00
parent a2f21e1286
commit a9baf6da95
8 changed files with 105 additions and 30 deletions

View File

@@ -5,7 +5,20 @@ server {
root /usr/share/nginx/html;
index index.html;
location = /taller {
return 301 /taller/;
}
location /taller/api/ {
proxy_pass http://backend:8000/;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location /taller/ {
try_files $uri $uri/ /index.html;
try_files $uri $uri/ /taller/index.html;
}
}

View File

@@ -16,5 +16,9 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
export const API_BASE = import.meta.env.VITE_API_BASE || 'http://localhost:8000';
const baseUrl = import.meta.env.BASE_URL || '/';
const defaultApiBase = `${baseUrl.replace(/\/$/, '')}/api`;
const rawApiBase = import.meta.env.VITE_API_BASE || defaultApiBase;
export const API_BASE = rawApiBase.replace(/\/$/, '');
export const ENABLE_POLLING = import.meta.env.MODE !== 'test';

View File

@@ -1,14 +1,34 @@
import { defineConfig } from 'vite';
import { defineConfig, loadEnv } from 'vite';
import { svelte } from '@sveltejs/vite-plugin-svelte';
export default defineConfig({
base: '/taller/',
plugins: [svelte()],
test: {
environment: 'jsdom',
globals: true,
},
server: {
port: 5173,
},
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), 'VITE_');
const basePath = '/taller/';
const defaultApiBase = `${basePath.replace(/\/$/, '')}/api`;
const apiBase = (env.VITE_API_BASE || defaultApiBase).replace(/\/$/, '');
const apiProxyPath = apiBase.startsWith('http') ? null : apiBase;
return {
base: basePath,
plugins: [svelte()],
test: {
environment: 'jsdom',
globals: true,
},
server: {
port: 5173,
proxy: apiProxyPath
? {
[apiProxyPath]: {
target: 'http://localhost:8000',
changeOrigin: true,
rewrite: (path) =>
path.startsWith(apiProxyPath)
? path.slice(apiProxyPath.length) || '/'
: path,
},
}
: undefined,
},
};
});