misskey/packages/frontend/vite.config.local-dev.ts

102 lines
2.2 KiB
TypeScript
Raw Normal View History

2023-12-08 00:22:08 +01:00
import dns from 'dns';
import { readFile } from 'node:fs/promises';
import type { IncomingMessage } from 'node:http';
2023-12-08 00:22:08 +01:00
import { defineConfig } from 'vite';
import type { UserConfig } from 'vite';
import * as yaml from 'js-yaml';
import locales from '../../locales/index.js';
2023-12-08 00:22:08 +01:00
import { getConfig } from './vite.config.js';
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}/`;
2024-08-26 10:36:35 +02:00
const embedUrl = `http://localhost:5174/`;
// 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 00:22:08 +01:00
// 基本の設定は vite.config.js から引き継ぐ
...defaultConfig,
root: 'src',
publicDir: '../assets',
base: './',
server: {
host: 'localhost',
port: 5173,
proxy: {
'/api': {
changeOrigin: true,
target: httpUrl,
2023-12-08 00:22:08 +01:00
},
'/assets': httpUrl,
'/static-assets': httpUrl,
'/client-assets': httpUrl,
'/files': httpUrl,
'/twemoji': httpUrl,
'/fluent-emoji': httpUrl,
'/sw.js': httpUrl,
2023-12-08 00:22:08 +01:00
'/streaming': {
target: websocketUrl,
2023-12-08 00:22:08 +01:00
ws: true,
},
'/favicon.ico': httpUrl,
2024-06-25 13:03:21 +02:00
'/robots.txt': httpUrl,
'/embed.js': httpUrl,
2024-08-27 01:24:34 +02:00
'/embed': {
target: embedUrl,
ws: true,
},
2023-12-08 00:22:08 +01:00
'/identicon': {
target: httpUrl,
2023-12-08 00:22:08 +01:00
rewrite(path) {
return path.replace('@localhost:5173', '');
},
},
'/url': httpUrl,
'/proxy': httpUrl,
'/_info_card_': httpUrl,
'/bios': httpUrl,
'/cli': httpUrl,
'/inbox': httpUrl,
'/emoji/': httpUrl,
2024-06-06 10:41:31 +02:00
'/notes': {
target: httpUrl,
bypass: varyHandler,
2024-06-06 10:41:31 +02:00
},
'/users': {
target: httpUrl,
bypass: varyHandler,
},
'/.well-known': {
target: httpUrl,
},
2023-12-08 00:22:08 +01:00
},
},
build: {
...defaultConfig.build,
rollupOptions: {
...defaultConfig.build?.rollupOptions,
input: 'index.html',
},
},
define: {
...defaultConfig.define,
_LANGS_FULL_: JSON.stringify(Object.entries(locales)),
},
2023-12-08 00:22:08 +01:00
};
export default defineConfig(({ command, mode }) => devConfig);