From 12a34961f82ec5bc3ce10158b0e1c7140646c850 Mon Sep 17 00:00:00 2001 From: TAKAHASHI Shuuji Date: Mon, 20 Jan 2025 19:10:29 +0900 Subject: [PATCH 1/2] =?UTF-8?q?fix!:=20default=20`server.cors:=20false`=20?= =?UTF-8?q?to=20disallow=20fetching=20from=20untruste=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit resolve #1809 https://github.com/vitejs/vite/commit/b09572acc939351f4e4c50ddf793017a92c678b1 の反映です。 --- config/server-options.md | 9 ++++++++- guide/backend-integration.md | 6 ++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/config/server-options.md b/config/server-options.md index 93bffa06..e80d5799 100644 --- a/config/server-options.md +++ b/config/server-options.md @@ -147,8 +147,15 @@ export default defineConfig({ ## server.cors - **型:** `boolean | CorsOptions` +- **デフォルト:** `false` + +開発サーバーの CORS を設定します。[オプションオブジェクト](https://github.com/expressjs/cors#configuration-options)を渡して微調整するか、`true` で有効にします。 + +:::warning + +信頼できないオリジンにソースコードを公開するのを避けるため、`true` ではなく特定の値をすることを推奨します。 +::: -開発サーバーの CORS を設定します。これはデフォルトで有効になっており、どんなオリジンも許可します。[オプションオブジェクト](https://github.com/expressjs/cors#configuration-options)を渡して微調整するか、`false` で無効にします。 ## server.headers diff --git a/guide/backend-integration.md b/guide/backend-integration.md index 7d7c9659..a71a9bb1 100644 --- a/guide/backend-integration.md +++ b/guide/backend-integration.md @@ -12,6 +12,12 @@ import { defineConfig } from 'vite' // ---cut--- export default defineConfig({ + server: { + cors: { + // ブラウザ経由でアクセスするオリジン + origin: 'http://my-backend.example.com', + }, + }, build: { // outDir に .vite/manifest.json を出力 manifest: true, From 0252a14e475b2414f379bc744070bb3b0d8e4f32 Mon Sep 17 00:00:00 2001 From: TAKAHASHI Shuuji Date: Tue, 21 Jan 2025 00:06:42 +0900 Subject: [PATCH 2/2] Update config/server-options.md Co-authored-by: Jun Shindo <46585162+jay-es@users.noreply.github.com> --- config/server-options.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/server-options.md b/config/server-options.md index e80d5799..c435ace5 100644 --- a/config/server-options.md +++ b/config/server-options.md @@ -149,7 +149,7 @@ export default defineConfig({ - **型:** `boolean | CorsOptions` - **デフォルト:** `false` -開発サーバーの CORS を設定します。[オプションオブジェクト](https://github.com/expressjs/cors#configuration-options)を渡して微調整するか、`true` で有効にします。 +開発サーバーの CORS を設定します。[オプションオブジェクト](https://github.com/expressjs/cors#configuration-options)を渡して微調整するか、`true` で任意のオリジンを許可します。 :::warning