restore support for local dev using a non-local url

This commit is contained in:
Hazelnoot 2025-02-06 12:57:44 -05:00
parent eaed8f2cec
commit 0d1c993dd2
3 changed files with 2 additions and 17 deletions

View file

@ -323,19 +323,16 @@ export class ClientServerService {
done(); done();
}); });
} else { } else {
const configUrl = new URL(this.config.url);
const urlOriginWithoutPort = configUrl.origin.replace(/:\d+$/, '');
const port = (process.env.VITE_PORT ?? '5173'); const port = (process.env.VITE_PORT ?? '5173');
fastify.register(fastifyProxy, { fastify.register(fastifyProxy, {
upstream: urlOriginWithoutPort + ':' + port, upstream: `http://localhost:${port}`,
prefix: '/vite', prefix: '/vite',
rewritePrefix: '/vite', rewritePrefix: '/vite',
}); });
const embedPort = (process.env.EMBED_VITE_PORT ?? '5174'); const embedPort = (process.env.EMBED_VITE_PORT ?? '5174');
fastify.register(fastifyProxy, { fastify.register(fastifyProxy, {
upstream: urlOriginWithoutPort + ':' + embedPort, upstream: `http://localhost:${embedPort}`,
prefix: '/embed_vite', prefix: '/embed_vite',
rewritePrefix: '/embed_vite', rewritePrefix: '/embed_vite',
}); });

View file

@ -2,8 +2,6 @@ import path from 'path';
import pluginVue from '@vitejs/plugin-vue'; import pluginVue from '@vitejs/plugin-vue';
import { type UserConfig, defineConfig } from 'vite'; import { type UserConfig, defineConfig } from 'vite';
import { localesVersion } from '../../locales/version.js'; import { localesVersion } from '../../locales/version.js';
import * as yaml from 'js-yaml';
import { promises as fsp } from 'fs';
import locales from '../../locales/index.js'; import locales from '../../locales/index.js';
import meta from '../../package.json'; import meta from '../../package.json';
@ -11,9 +9,6 @@ import packageInfo from './package.json' with { type: 'json' };
import pluginJson5 from './vite.json5.js'; import pluginJson5 from './vite.json5.js';
import { pluginReplaceIcons } from '../frontend/vite.replaceIcons.js'; import { pluginReplaceIcons } from '../frontend/vite.replaceIcons.js';
const url = process.env.NODE_ENV === 'development' ? yaml.load(await fsp.readFile('../../.config/default.yml', 'utf-8')).url : null;
const host = url ? (new URL(url)).hostname : undefined;
const extensions = ['.ts', '.tsx', '.js', '.jsx', '.mjs', '.json', '.json5', '.svg', '.sass', '.scss', '.css', '.vue']; const extensions = ['.ts', '.tsx', '.js', '.jsx', '.mjs', '.json', '.json5', '.svg', '.sass', '.scss', '.css', '.vue'];
/** /**
@ -69,7 +64,6 @@ export function getConfig(): UserConfig {
base: '/embed_vite/', base: '/embed_vite/',
server: { server: {
host,
port: 5174, port: 5174,
hmr: { hmr: {
// バックエンド経由での起動時、Viteは5174経由でアセットを参照していると思い込んでいるが実際は3000から配信される // バックエンド経由での起動時、Viteは5174経由でアセットを参照していると思い込んでいるが実際は3000から配信される

View file

@ -3,8 +3,6 @@ import pluginReplace from '@rollup/plugin-replace';
import pluginVue from '@vitejs/plugin-vue'; import pluginVue from '@vitejs/plugin-vue';
import { type UserConfig, defineConfig } from 'vite'; import { type UserConfig, defineConfig } from 'vite';
import { localesVersion } from '../../locales/version.js'; import { localesVersion } from '../../locales/version.js';
import * as yaml from 'js-yaml';
import { promises as fsp } from 'fs';
import locales from '../../locales/index.js'; import locales from '../../locales/index.js';
import meta from '../../package.json'; import meta from '../../package.json';
@ -13,9 +11,6 @@ import pluginUnwindCssModuleClassName from './lib/rollup-plugin-unwind-css-modul
import pluginJson5 from './vite.json5.js'; import pluginJson5 from './vite.json5.js';
import { pluginReplaceIcons } from './vite.replaceIcons.js'; import { pluginReplaceIcons } from './vite.replaceIcons.js';
const url = process.env.NODE_ENV === 'development' ? yaml.load(await fsp.readFile('../../.config/default.yml', 'utf-8')).url : null;
const host = url ? (new URL(url)).hostname : undefined;
const extensions = ['.ts', '.tsx', '.js', '.jsx', '.mjs', '.json', '.json5', '.svg', '.sass', '.scss', '.css', '.vue', '.wasm']; const extensions = ['.ts', '.tsx', '.js', '.jsx', '.mjs', '.json', '.json5', '.svg', '.sass', '.scss', '.css', '.vue', '.wasm'];
/** /**
@ -82,7 +77,6 @@ export function getConfig(): UserConfig {
base: '/vite/', base: '/vite/',
server: { server: {
host,
port: 5173, port: 5173,
hmr: { hmr: {
// バックエンド経由での起動時、Viteは5173経由でアセットを参照していると思い込んでいるが実際は3000から配信される // バックエンド経由での起動時、Viteは5173経由でアセットを参照していると思い込んでいるが実際は3000から配信される