From aaa3dc2fb95cff6d156670878e2538179424eef6 Mon Sep 17 00:00:00 2001 From: chan Date: Mon, 6 Apr 2026 11:47:33 +0900 Subject: [PATCH] fix: use vite preview in staging to support api proxy in frontends --- adminfront/scripts/runtime-mode.sh | 4 ++-- adminfront/vite.config.ts | 14 ++++++++++++-- devfront/scripts/runtime-mode.sh | 4 ++-- devfront/vite.config.ts | 16 +++++++++++++--- 4 files changed, 29 insertions(+), 9 deletions(-) diff --git a/adminfront/scripts/runtime-mode.sh b/adminfront/scripts/runtime-mode.sh index 7e253a5d..aa41dce1 100644 --- a/adminfront/scripts/runtime-mode.sh +++ b/adminfront/scripts/runtime-mode.sh @@ -18,8 +18,8 @@ if [ "${1:-}" = "--print-mode" ]; then fi if [ "$mode" = "production" ]; then - echo "Running in production mode..." - exec sh -c "npm run build && serve -s dist -l 5173" + echo "Running in production mode with Vite preview..." + exec sh -c "npm run build && npm run preview -- --host 0.0.0.0" fi echo "Running in development mode..." diff --git a/adminfront/vite.config.ts b/adminfront/vite.config.ts index 2cc12b24..2a8338a8 100644 --- a/adminfront/vite.config.ts +++ b/adminfront/vite.config.ts @@ -1,13 +1,23 @@ import react from "@vitejs/plugin-react"; import { defineConfig } from "vite"; -// https://vite.dev/config/ export default defineConfig({ plugins: [react()], envPrefix: ["VITE_", "USERFRONT_"], server: { host: "0.0.0.0", - allowedHosts: ["sadmin.hmac.kr", "localhost", "172.16.10.176"], + allowedHosts: ["sadmin.hmac.kr", "localhost", "172.16.10.176", "127.0.0.1"], + proxy: { + "/api": { + target: process.env.API_PROXY_TARGET || "http://localhost:3000", + changeOrigin: true, + }, + }, + }, + preview: { + host: "0.0.0.0", + port: 5173, + allowedHosts: ["sadmin.hmac.kr", "localhost", "172.16.10.176", "127.0.0.1"], proxy: { "/api": { target: process.env.API_PROXY_TARGET || "http://localhost:3000", diff --git a/devfront/scripts/runtime-mode.sh b/devfront/scripts/runtime-mode.sh index 7e253a5d..aa41dce1 100644 --- a/devfront/scripts/runtime-mode.sh +++ b/devfront/scripts/runtime-mode.sh @@ -18,8 +18,8 @@ if [ "${1:-}" = "--print-mode" ]; then fi if [ "$mode" = "production" ]; then - echo "Running in production mode..." - exec sh -c "npm run build && serve -s dist -l 5173" + echo "Running in production mode with Vite preview..." + exec sh -c "npm run build && npm run preview -- --host 0.0.0.0" fi echo "Running in development mode..." diff --git a/devfront/vite.config.ts b/devfront/vite.config.ts index 03238f1d..7ea28ab7 100644 --- a/devfront/vite.config.ts +++ b/devfront/vite.config.ts @@ -1,12 +1,22 @@ import react from "@vitejs/plugin-react"; import { defineConfig } from "vite"; -// https://vite.dev/config/ export default defineConfig({ plugins: [react()], server: { - host: "0.0.0.0", // Ensure binding to all interfaces - allowedHosts: ["sdev.hmac.kr", "localhost", "172.16.10.176"], + host: "0.0.0.0", + allowedHosts: ["sdev.hmac.kr", "localhost", "172.16.10.176", "127.0.0.1"], + proxy: { + "/api": { + target: process.env.API_PROXY_TARGET || "http://localhost:3000", + changeOrigin: true, + }, + }, + }, + preview: { + host: "0.0.0.0", + port: 5173, + allowedHosts: ["sdev.hmac.kr", "localhost", "172.16.10.176", "127.0.0.1"], proxy: { "/api": { target: process.env.API_PROXY_TARGET || "http://localhost:3000",