Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Jul 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions packages/frontend/vite.config.local-dev.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import dns from 'dns';
import { readFile } from 'node:fs/promises';
import type { IncomingMessage } from 'node:http';
import { defineConfig } from 'vite';
import type { UserConfig } from 'vite';
import * as yaml from 'js-yaml';
import locales from '../../locales/index.js';
import { getConfig } from './vite.config.js';
Expand All @@ -14,7 +16,15 @@ const { port } = yaml.load(await readFile('../../.config/default.yml', 'utf-8'))
const httpUrl = `http://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 から引き継ぐ
...defaultConfig,
root: 'src',
Expand Down Expand Up @@ -54,15 +64,11 @@ const devConfig = {
'/inbox': httpUrl,
'/notes': {
target: httpUrl,
headers: {
'Accept': 'application/activity+json',
},
bypass: varyHandler,
},
'/users': {
target: httpUrl,
headers: {
'Accept': 'application/activity+json',
},
bypass: varyHandler,
},
'/.well-known': {
target: httpUrl,
Expand Down
Loading