From 3e00b32faeb416c15ee75346ccd4c135bdfe576a Mon Sep 17 00:00:00 2001
From: anatawa12 <anatawa12@icloud.com>
Date: Fri, 3 Nov 2023 13:34:57 +0900
Subject: [PATCH] build: port vite port configuration (#12223)

---
 packages/backend/src/server/web/ClientServerService.ts | 3 ++-
 scripts/dev.mjs                                        | 4 +++-
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/packages/backend/src/server/web/ClientServerService.ts b/packages/backend/src/server/web/ClientServerService.ts
index cf621f4579..7a2a52a982 100644
--- a/packages/backend/src/server/web/ClientServerService.ts
+++ b/packages/backend/src/server/web/ClientServerService.ts
@@ -253,8 +253,9 @@ export class ClientServerService {
 				decorateReply: false,
 			});
 		} else {
+			const port = (process.env.VITE_PORT ?? '5173');
 			fastify.register(fastifyProxy, {
-				upstream: 'http://localhost:5173', // TODO: port configuration
+				upstream: 'http://localhost:' + port,
 				prefix: '/vite',
 				rewritePrefix: '/vite',
 			});
diff --git a/scripts/dev.mjs b/scripts/dev.mjs
index 26f29fc491..1d06aa541f 100644
--- a/scripts/dev.mjs
+++ b/scripts/dev.mjs
@@ -11,6 +11,8 @@ import { execa } from 'execa';
 const _filename = fileURLToPath(import.meta.url);
 const _dirname = dirname(_filename);
 
+const vitePort = process.env.VITE_PORT ? ["--strictPort", "--port", process.env.VITE_PORT] : ["--strictPort"];
+
 await execa('pnpm', ['clean'], {
 	cwd: _dirname + '/../',
 	stdout: process.stdout,
@@ -41,7 +43,7 @@ execa('pnpm', ['--filter', 'backend', 'watch'], {
 	stderr: process.stderr,
 });
 
-execa('pnpm', ['--filter', 'frontend', 'watch'], {
+execa('pnpm', ['--filter', 'frontend', 'watch', ...vitePort], {
 	cwd: _dirname + '/../',
 	stdout: process.stdout,
 	stderr: process.stderr,
-- 
GitLab