2023-12-08 08:22:08 +09:00
|
|
|
import dns from 'dns';
|
2024-01-29 21:39:34 +09:00
|
|
|
import { readFile } from 'node:fs/promises';
|
2024-07-06 11:46:43 +09:00
|
|
|
import type { IncomingMessage } from 'node:http';
|
2023-12-08 08:22:08 +09:00
|
|
|
import { defineConfig } from 'vite';
|
2024-07-06 11:46:43 +09:00
|
|
|
import type { UserConfig } from 'vite';
|
2024-01-29 21:39:34 +09:00
|
|
|
import * as yaml from 'js-yaml';
|
2023-12-24 16:16:58 +09:00
|
|
|
import locales from '../../locales/index.js';
|
2023-12-08 08:22:08 +09:00
|
|
|
import { getConfig } from './vite.config.js';
|
|
|
|
|
|
|
|
dns.setDefaultResultOrder('ipv4first');
|
|
|
|
|
|
|
|
const defaultConfig = getConfig();
|
|
|
|
|
2024-01-29 21:39:34 +09:00
|
|
|
const { port } = yaml.load(await readFile('../../.config/default.yml', 'utf-8'));
|
|
|
|
|
|
|
|
const httpUrl = `http://localhost:${port}/`;
|
|
|
|
const websocketUrl = `ws://localhost:${port}/`;
|
2024-08-26 17:36:35 +09:00
|
|
|
const embedUrl = `http://localhost:5174/`;
|
2024-01-29 21:39:34 +09:00
|
|
|
|
2024-07-06 11:46:43 +09:00
|
|
|
// activitypubリクエストはProxyを通し、それ以外はViteの開発サーバーを返す
|
|
|
|
function varyHandler(req: IncomingMessage) {
|
|
|
|
if (req.headers.accept?.includes('application/activity+json')) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return '/index.html';
|
|
|
|
}
|
|
|
|
|
|
|
|
const devConfig: UserConfig = {
|
2023-12-08 08:22:08 +09:00
|
|
|
// 基本の設定は vite.config.js から引き継ぐ
|
|
|
|
...defaultConfig,
|
|
|
|
root: 'src',
|
|
|
|
publicDir: '../assets',
|
|
|
|
base: './',
|
|
|
|
server: {
|
|
|
|
host: 'localhost',
|
|
|
|
port: 5173,
|
|
|
|
proxy: {
|
|
|
|
'/api': {
|
|
|
|
changeOrigin: true,
|
2024-01-29 21:39:34 +09:00
|
|
|
target: httpUrl,
|
2023-12-08 08:22:08 +09:00
|
|
|
},
|
2024-01-29 21:39:34 +09:00
|
|
|
'/assets': httpUrl,
|
|
|
|
'/static-assets': httpUrl,
|
|
|
|
'/client-assets': httpUrl,
|
|
|
|
'/files': httpUrl,
|
|
|
|
'/twemoji': httpUrl,
|
|
|
|
'/fluent-emoji': httpUrl,
|
|
|
|
'/sw.js': httpUrl,
|
2023-12-08 08:22:08 +09:00
|
|
|
'/streaming': {
|
2024-01-29 21:39:34 +09:00
|
|
|
target: websocketUrl,
|
2023-12-08 08:22:08 +09:00
|
|
|
ws: true,
|
|
|
|
},
|
2024-01-29 21:39:34 +09:00
|
|
|
'/favicon.ico': httpUrl,
|
2024-06-25 20:03:21 +09:00
|
|
|
'/robots.txt': httpUrl,
|
|
|
|
'/embed.js': httpUrl,
|
2024-08-27 08:24:34 +09:00
|
|
|
'/embed': {
|
|
|
|
target: embedUrl,
|
|
|
|
ws: true,
|
|
|
|
},
|
2023-12-08 08:22:08 +09:00
|
|
|
'/identicon': {
|
2024-01-29 21:39:34 +09:00
|
|
|
target: httpUrl,
|
2023-12-08 08:22:08 +09:00
|
|
|
rewrite(path) {
|
|
|
|
return path.replace('@localhost:5173', '');
|
|
|
|
},
|
|
|
|
},
|
2024-01-29 21:39:34 +09:00
|
|
|
'/url': httpUrl,
|
|
|
|
'/proxy': httpUrl,
|
2024-03-05 17:27:33 +09:00
|
|
|
'/_info_card_': httpUrl,
|
|
|
|
'/bios': httpUrl,
|
|
|
|
'/cli': httpUrl,
|
2024-04-27 20:26:55 +09:00
|
|
|
'/inbox': httpUrl,
|
2024-07-25 17:03:00 +09:00
|
|
|
'/emoji/': httpUrl,
|
2024-06-06 17:41:31 +09:00
|
|
|
'/notes': {
|
2024-04-27 20:26:55 +09:00
|
|
|
target: httpUrl,
|
2024-07-06 11:46:43 +09:00
|
|
|
bypass: varyHandler,
|
2024-06-06 17:41:31 +09:00
|
|
|
},
|
2024-04-27 20:26:55 +09:00
|
|
|
'/users': {
|
|
|
|
target: httpUrl,
|
2024-07-06 11:46:43 +09:00
|
|
|
bypass: varyHandler,
|
2024-04-27 20:26:55 +09:00
|
|
|
},
|
|
|
|
'/.well-known': {
|
|
|
|
target: httpUrl,
|
|
|
|
},
|
2023-12-08 08:22:08 +09:00
|
|
|
},
|
|
|
|
},
|
|
|
|
build: {
|
|
|
|
...defaultConfig.build,
|
|
|
|
rollupOptions: {
|
|
|
|
...defaultConfig.build?.rollupOptions,
|
|
|
|
input: 'index.html',
|
|
|
|
},
|
|
|
|
},
|
2023-12-14 20:16:02 +09:00
|
|
|
|
|
|
|
define: {
|
|
|
|
...defaultConfig.define,
|
|
|
|
_LANGS_FULL_: JSON.stringify(Object.entries(locales)),
|
|
|
|
},
|
2023-12-08 08:22:08 +09:00
|
|
|
};
|
|
|
|
|
|
|
|
export default defineConfig(({ command, mode }) => devConfig);
|
|
|
|
|