test(frontend): load default config to start vite (#12867)

Co-authored-by: おさむのひと <46447427+samunohito@users.noreply.github.com>
This commit is contained in:
Kagami Sascha Rosylight 2024-01-29 13:39:34 +01:00 committed by GitHub
parent 4535f9b41b
commit e21cecefa1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,5 +1,7 @@
import dns from 'dns'; import dns from 'dns';
import { readFile } from 'node:fs/promises';
import { defineConfig } from 'vite'; import { defineConfig } from 'vite';
import * as yaml from 'js-yaml';
import locales from '../../locales/index.js'; import locales from '../../locales/index.js';
import { getConfig } from './vite.config.js'; import { getConfig } from './vite.config.js';
@ -7,6 +9,11 @@ dns.setDefaultResultOrder('ipv4first');
const defaultConfig = getConfig(); 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 = { const devConfig = {
// 基本の設定は vite.config.js から引き継ぐ // 基本の設定は vite.config.js から引き継ぐ
...defaultConfig, ...defaultConfig,
@ -19,28 +26,28 @@ const devConfig = {
proxy: { proxy: {
'/api': { '/api': {
changeOrigin: true, changeOrigin: true,
target: 'http://localhost:3000/', target: httpUrl,
}, },
'/assets': 'http://localhost:3000/', '/assets': httpUrl,
'/static-assets': 'http://localhost:3000/', '/static-assets': httpUrl,
'/client-assets': 'http://localhost:3000/', '/client-assets': httpUrl,
'/files': 'http://localhost:3000/', '/files': httpUrl,
'/twemoji': 'http://localhost:3000/', '/twemoji': httpUrl,
'/fluent-emoji': 'http://localhost:3000/', '/fluent-emoji': httpUrl,
'/sw.js': 'http://localhost:3000/', '/sw.js': httpUrl,
'/streaming': { '/streaming': {
target: 'ws://localhost:3000/', target: websocketUrl,
ws: true, ws: true,
}, },
'/favicon.ico': 'http://localhost:3000/', '/favicon.ico': httpUrl,
'/identicon': { '/identicon': {
target: 'http://localhost:3000/', target: httpUrl,
rewrite(path) { rewrite(path) {
return path.replace('@localhost:5173', ''); return path.replace('@localhost:5173', '');
}, },
}, },
'/url': 'http://localhost:3000', '/url': httpUrl,
'/proxy': 'http://localhost:3000', '/proxy': httpUrl,
}, },
}, },
build: { build: {