From e21cecefa1a395be58918730c07404720220128b Mon Sep 17 00:00:00 2001 From: Kagami Sascha Rosylight Date: Mon, 29 Jan 2024 13:39:34 +0100 Subject: [PATCH] test(frontend): load default config to start vite (#12867) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: おさむのひと <46447427+samunohito@users.noreply.github.com> --- packages/frontend/vite.config.local-dev.ts | 33 +++++++++++++--------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/packages/frontend/vite.config.local-dev.ts b/packages/frontend/vite.config.local-dev.ts index 5a6f511c66..6d9488797c 100644 --- a/packages/frontend/vite.config.local-dev.ts +++ b/packages/frontend/vite.config.local-dev.ts @@ -1,5 +1,7 @@ import dns from 'dns'; +import { readFile } from 'node:fs/promises'; import { defineConfig } from 'vite'; +import * as yaml from 'js-yaml'; import locales from '../../locales/index.js'; import { getConfig } from './vite.config.js'; @@ -7,6 +9,11 @@ dns.setDefaultResultOrder('ipv4first'); const defaultConfig = getConfig(); +const { port } = yaml.load(await readFile('../../.config/default.yml', 'utf-8')); + +const httpUrl = `http://localhost:${port}/`; +const websocketUrl = `ws://localhost:${port}/`; + const devConfig = { // 基本の設定は vite.config.js から引き継ぐ ...defaultConfig, @@ -19,28 +26,28 @@ const devConfig = { proxy: { '/api': { changeOrigin: true, - target: 'http://localhost:3000/', + target: httpUrl, }, - '/assets': 'http://localhost:3000/', - '/static-assets': 'http://localhost:3000/', - '/client-assets': 'http://localhost:3000/', - '/files': 'http://localhost:3000/', - '/twemoji': 'http://localhost:3000/', - '/fluent-emoji': 'http://localhost:3000/', - '/sw.js': 'http://localhost:3000/', + '/assets': httpUrl, + '/static-assets': httpUrl, + '/client-assets': httpUrl, + '/files': httpUrl, + '/twemoji': httpUrl, + '/fluent-emoji': httpUrl, + '/sw.js': httpUrl, '/streaming': { - target: 'ws://localhost:3000/', + target: websocketUrl, ws: true, }, - '/favicon.ico': 'http://localhost:3000/', + '/favicon.ico': httpUrl, '/identicon': { - target: 'http://localhost:3000/', + target: httpUrl, rewrite(path) { return path.replace('@localhost:5173', ''); }, }, - '/url': 'http://localhost:3000', - '/proxy': 'http://localhost:3000', + '/url': httpUrl, + '/proxy': httpUrl, }, }, build: {