fix(dev): devサーバーで`/notes/`に直でアクセスしたらサーバー側のレスポンスが返ってくる問題を修正 (#14137)

This commit is contained in:
かっこかり 2024-07-06 11:46:43 +09:00 committed by GitHub
parent 6dd2e9fc0b
commit b9ed3b2427
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 13 additions and 7 deletions

View File

@ -1,6 +1,8 @@
import dns from 'dns'; import dns from 'dns';
import { readFile } from 'node:fs/promises'; import { readFile } from 'node:fs/promises';
import type { IncomingMessage } from 'node:http';
import { defineConfig } from 'vite'; import { defineConfig } from 'vite';
import type { UserConfig } from 'vite';
import * as yaml from 'js-yaml'; 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';
@ -14,7 +16,15 @@ const { port } = yaml.load(await readFile('../../.config/default.yml', 'utf-8'))
const httpUrl = `http://localhost:${port}/`; const httpUrl = `http://localhost:${port}/`;
const websocketUrl = `ws://localhost:${port}/`; const websocketUrl = `ws://localhost:${port}/`;
const devConfig = { // activitypubリクエストはProxyを通し、それ以外はViteの開発サーバーを返す
function varyHandler(req: IncomingMessage) {
if (req.headers.accept?.includes('application/activity+json')) {
return null;
}
return '/index.html';
}
const devConfig: UserConfig = {
// 基本の設定は vite.config.js から引き継ぐ // 基本の設定は vite.config.js から引き継ぐ
...defaultConfig, ...defaultConfig,
root: 'src', root: 'src',
@ -54,15 +64,11 @@ const devConfig = {
'/inbox': httpUrl, '/inbox': httpUrl,
'/notes': { '/notes': {
target: httpUrl, target: httpUrl,
headers: { bypass: varyHandler,
'Accept': 'application/activity+json',
},
}, },
'/users': { '/users': {
target: httpUrl, target: httpUrl,
headers: { bypass: varyHandler,
'Accept': 'application/activity+json',
},
}, },
'/.well-known': { '/.well-known': {
target: httpUrl, target: httpUrl,