feat(deploy): configurable backend HOST + env-driven vite base/assetsDir
- backend: HOST env (default 127.0.0.1, dev-safe; 0.0.0.0 in container) - frontend: VITE_BASE drives base/assetsDir/manifest for portal embedding - backward compatible: no env => identical to previous behavior
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
export interface AppConfig {
|
export interface AppConfig {
|
||||||
port: number; harnessDir: string; thtBin: string; piBin: string;
|
host: string; port: number; harnessDir: string; thtBin: string; piBin: string;
|
||||||
authMode: "none" | "mock" | "oidc";
|
authMode: "none" | "mock" | "oidc";
|
||||||
defaults: { provider?: string; model?: string; thinking?: string };
|
defaults: { provider?: string; model?: string; thinking?: string };
|
||||||
maxPiProcesses: number;
|
maxPiProcesses: number;
|
||||||
@@ -8,6 +8,7 @@ export interface AppConfig {
|
|||||||
}
|
}
|
||||||
export function loadConfig(env: Record<string, string | undefined>): AppConfig {
|
export function loadConfig(env: Record<string, string | undefined>): AppConfig {
|
||||||
return {
|
return {
|
||||||
|
host: env.HOST ?? "127.0.0.1",
|
||||||
port: Number(env.PORT ?? 8787),
|
port: Number(env.PORT ?? 8787),
|
||||||
harnessDir: env.THT_HARNESS_DIR ?? "../harness",
|
harnessDir: env.THT_HARNESS_DIR ?? "../harness",
|
||||||
thtBin: env.THT_BIN ?? "tht",
|
thtBin: env.THT_BIN ?? "tht",
|
||||||
|
|||||||
@@ -2,5 +2,5 @@ import { buildApp } from "./app.js";
|
|||||||
import { loadConfig } from "./config.js";
|
import { loadConfig } from "./config.js";
|
||||||
const config = loadConfig(process.env);
|
const config = loadConfig(process.env);
|
||||||
const app = buildApp(config);
|
const app = buildApp(config);
|
||||||
app.listen({ port: config.port, host: "127.0.0.1" })
|
app.listen({ port: config.port, host: config.host })
|
||||||
.then((addr) => console.log(`backend listening on ${addr}`));
|
.then((addr) => console.log(`backend listening on ${addr}`));
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
import { test, expect } from "vitest";
|
||||||
|
import { loadConfig } from "../src/config.js";
|
||||||
|
|
||||||
|
test("loadConfig espone host con default dev-safe 127.0.0.1", () => {
|
||||||
|
expect(loadConfig({})).toMatchObject({ host: "127.0.0.1" });
|
||||||
|
});
|
||||||
|
|
||||||
|
test("loadConfig rispetta HOST esplicito (necessario in container)", () => {
|
||||||
|
expect(loadConfig({ HOST: "0.0.0.0" })).toMatchObject({ host: "0.0.0.0" });
|
||||||
|
});
|
||||||
|
|
||||||
|
test("loadConfig merge altri campi con l'host", () => {
|
||||||
|
expect(
|
||||||
|
loadConfig({ HOST: "0.0.0.0", THT_BIN: "/opt/venv/bin/tht", PORT: "9000" })
|
||||||
|
).toMatchObject({
|
||||||
|
host: "0.0.0.0",
|
||||||
|
thtBin: "/opt/venv/bin/tht",
|
||||||
|
port: 9000,
|
||||||
|
});
|
||||||
|
});
|
||||||
+11
-7
@@ -2,11 +2,15 @@ import { defineConfig } from "vite";
|
|||||||
import react from "@vitejs/plugin-react";
|
import react from "@vitejs/plugin-react";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig(() => {
|
||||||
plugins: [react()],
|
const embedBase = process.env.VITE_BASE; // "/datamart-builder/assets/" in embedded; undefined = standalone
|
||||||
resolve: {
|
return {
|
||||||
alias: {
|
plugins: [react()],
|
||||||
"@": path.resolve(__dirname, "./src"),
|
// base: prefisso pubblico degli asset. Default "/" (standalone).
|
||||||
},
|
// assetsDir vuoto in embedded → asset alla root di dist/ così il proxy
|
||||||
},
|
// /datamart-builder/assets/ → frontend-root mappa 1:1 (niente /assets/assets/).
|
||||||
|
base: embedBase ?? "/",
|
||||||
|
build: { manifest: true, outDir: "dist", assetsDir: embedBase ? "" : "assets" },
|
||||||
|
resolve: { alias: { "@": path.resolve(__dirname, "./src") } },
|
||||||
|
};
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user