-
Notifications
You must be signed in to change notification settings - Fork 3
フロントエンドとバックエンドの連携とデプロイの節を追加 #890
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
base: main
Are you sure you want to change the base?
Conversation
Deploying utcode-learn with
|
| Latest commit: |
643f2e8
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://50bd2739.utcode-learn.pages.dev |
| Branch Preview URL: | https://add-deploy-chapter.utcode-learn.pages.dev |
89884e6 to
a54ea15
Compare
e0beb3e to
e53da51
Compare
docs/4-advanced/05-integration-and-deployment/_samples/fullstack-app/frontend/src/App.tsx
Show resolved
Hide resolved
e53da51 to
28be016
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds a comprehensive new section on "Frontend and Backend Integration and Deployment" to the advanced documentation. The changes include term definitions for key concepts like tsx (TypeScript Execute), origins, and CORS, along with supporting visual materials and sample code for a fullstack application.
Key Changes
- Added three new technical term definitions (tsx, origin, CORS) with Japanese descriptions and reference links
- Included visual assets (PNG diagram and SVG flowchart) to illustrate web service architecture and data flow
- Provided a React component to visually explain the concept of origins
- Added frontend boilerplate configuration files (TypeScript configs, Vite setup, package.json)
Reviewed Changes
Copilot reviewed 22 out of 32 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/components/Term/type-map.js | Maps new terms (tsx, オリジン, CORS) to their definition keys |
| src/components/Term/definitions.js | Defines technical terms with Japanese descriptions and reference pages |
| docs/4-advanced/05-integration-and-deployment/web-service.png | Binary image file showing web service architecture |
| docs/4-advanced/05-integration-and-deployment/simple-forum-app-flow.drawio.svg | SVG diagram illustrating application data flow between user, servers, and database |
| docs/4-advanced/05-integration-and-deployment/origin-explanation.tsx | React component providing interactive explanation of URL origin components |
| docs/4-advanced/05-integration-and-deployment/_samples/fullstack-app/frontend/* | Frontend sample application configuration files including TypeScript configs, Vite setup, and package.json |
Files not reviewed (1)
- docs/4-advanced/05-integration-and-deployment/_samples/fullstack-app/backend/package-lock.json: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
nakaterm
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
細かい部分のコラムでの説明も行き届いていてやっぱりさすがだなという感じです ✨
コメントしました!
chelproc
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
見ました!
ちなみに新しい技術の導入ですが、「XX は YYYY です」とすると「その定義あってる?」となりがちなので、「XX を用いると、YYYY できます」とか、「YYYY するには、XX を使用します」とかすると良かったりします。
|
|
||
| datasource db { | ||
| provider = "postgresql" | ||
| url = env("DATABASE_URL") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
↓のようなエラーが出るのですが大丈夫そうでしょうか??
The datasource property
urlis no longer supported in schema files. Move connection URLs for Migrate toprisma.config.tsand pass eitheradapterfor a direct database connection oraccelerateUrlfor Accelerate to thePrismaClientconstructor. See https://pris.ly/d/config-datasource and https://pris.ly/d/prisma7-client-configPrisma
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prisma 7.0.0以降だとそのようになるようです。Prisma 7.1.0に対応したことで、修正されました!
|
|
||
| app.post("/send", async (request, response) => { | ||
| await client.post.create({ data: { message: request.body.message } }); | ||
| response.send(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sendStatus(201); ?
| response.json(posts); | ||
| }); | ||
|
|
||
| app.post("/send", async (request, response) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RESTful なら POST /posts なのでそうすべき?
|
|
||
| ## フロントエンドとバックエンドを連携する | ||
|
|
||
| Reactによって作成されたブラウザ上で動くアプリケーションと、Node.jsによって作成されたサーバー上で動くアプリケーションを接続する方法について学びましょう。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
「フロントエンド」「バックエンド」という言葉は導入済みなので使ってしまっても良いのでは?
|
|
||
|  | ||
|
|
||
| 今回作成する掲示板サービスでは、フロントエンドとバックエンドでそれぞれ別のWebサーバーを起動します。バックエンドはNode.jsを用いてWebサーバーを起動し、フロントエンドはViteを用いて開発用サーバーを起動します。処理の流れは、次の図のようになります。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
「起動」は運用により過ぎた表現な気がします。また、フロントエンドは開発環境のみ触れられており本番環境がどう動作するのかが分かりづらい気がします。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ここでは簡単のため開発環境のみの場合に絞って説明していたのですが、やはりわかりづらいため、単に「今回作成する掲示板サービスでは、フロントエンドとバックエンドでそれぞれ別のサーバーを構築します。処理の流れは、次の図のようになります。」のような説明にしてみます 👍
|
|
||
| Viteでは[`VITE_`で始まる<Term>環境変数</Term>を`import.meta.env`オブジェクトのプロパティとして利用](https://ja.vite.dev/guide/env-and-mode.html#env-variables)できます。例えば、`VITE_API_ENDPOINT`という<Term>環境変数</Term>がある場合、`import.meta.env.VITE_API_ENDPOINT`として参照できます。 | ||
|
|
||
| なお、Viteは起動時に`.env`ファイルの内容を自動的に読み込みます。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- 「Viteは起動時に
.envファイルの内容を環境変数として読み込みます。」が先の方が自然かなと。 - 「Viteでは - できます」の繋がりが若干不正確かなと。「Viteは、
VITE_で始まる環境変数を、アプリケーション内でimport.meta.envオブジェクトのプロパティとして利用できるようにします。」
|
|
||
| ## デプロイする | ||
|
|
||
| 今までは、バックエンドとフロントエンドのそれぞれで`npm run dev`コマンドを実行することで、バックエンドの場合にはTypeScriptファイルを直接実行してWebサーバーを起動し、フロントエンドの場合にはViteの開発用サーバーを起動していました。しかしながら、<Term>デプロイ</Term>する際には、これとは異なる方法を用いる必要があります。バックエンドの場合には、TypeScriptファイルをJavaScriptファイルに<Term>トランスパイル</Term>してから、そのJavaScriptファイルを実行します。フロントエンドの場合には、Viteにより出力されたファイルを配信します。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
いずれも別に必須ではないです(バックエンドはtsxで問題なく動きますし、viteの開発用サーバーも本番用としても使えないこともないです)。「本番環境ではxxxすることが一般的です」という表現が妥当かなと!可能であれば、まず本番の説明があり、その後開発用サーバーがその代わりとしてどう動くのかを説明する順序の方が素直かなと思います。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
この節の構成が、開発環境を構築してから(開発環境の構成を理解してから)、本番環境を構築するという順番になっているため、先に本番環境の説明をすることは難しそうです。
|
|
||
| | 環境 | バックエンド | フロントエンド | | ||
| | -------- | --------------------------------------------------------------------------- | ---------------------------------- | | ||
| | 開発環境 | TypeScriptファイルを直接実行してWebサーバーを起動 | Viteの開発用サーバーを起動 | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- 「TypeScriptファイルを直接実行」よりは「tsxパッケージを用いて実行」の方がよいかと思います。
- フロントエンドではRender自身がWebサーバーとして機能していることを明示した方が良いかもしれません。
|
|
||
| :::tip[`prisma generate`コマンド] | ||
|
|
||
| [`prisma generate`コマンド](https://www.prisma.io/docs/orm/reference/prisma-cli-reference#generate)は、`schema.prisma`ファイルの内容に基づいて`Prisma Client`クラスを生成します。通常、`schema.prisma`ファイルを編集するたびにこのコマンドを再度実行して`Prisma Client`クラスを再生成する必要があります。ただし、`prisma db push`コマンドを実行する際にも`Prisma Client`クラスは生成されるため、`prisma db push`コマンドを実行した場合には`prisma generate`コマンドを実行する必要はありません。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
「Prisma Clientクラス」は表現として適切でないかもです!
一応正確には「そのテーブル構造に基づいて専用のクライアントを生成します」とかになるのかなと。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
すみません...
PrismaClientクラスとPrisma Clientを完全に混同していました。
|
|
||
| ### ビルドの設定をする | ||
|
|
||
| フロントエンドの場合には、`npm run build`コマンドを実行することで、Viteにより<Term>トランスパイル</Term>とバンドルの結果が`dist`ディレクトリに格納されるのでした。<Term>デプロイ</Term>の際には、この`dist`ディレクトリを配信すればよいです。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- この文脈だとトランスパイルとバンドルを分けて語ることは少ない気がします。「ビルド結果」とかでいいんじゃないでしょうか。
- 「デプロイ」は本番環境を作る瞬間のことなので、「distディレクトリの配信」は「デプロイ後の状況」であって、「デプロイの際」ではないかなと思います。「本番環境では
distディレクトリの内容を配信」とかが良いかなと
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
一応ビルドということばは初出だったためこのように書いたのですが、やはり、「ビルド結果」のように書きます。
本番環境ということばも初出ではありますが、表ですでに使ってしまっているため、ここでも使用しようかと思います。
|
今までのレビューの内容をすべて直しました。また、動画なども加え、完成しています。再度レビューをお願いします! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 25 out of 51 changed files in this pull request and generated 3 comments.
Files not reviewed (2)
- docs/4-advanced/04-react/_samples/todo-database/backend/package-lock.json: Language not supported
- docs/4-advanced/05-integration-and-deployment/_samples/fullstack-app/backend/package-lock.json: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
docs/4-advanced/05-integration-and-deployment/_samples/fullstack-app/frontend/.env
Show resolved
Hide resolved
docs/4-advanced/05-integration-and-deployment/_samples/fullstack-app/frontend/src/App.tsx
Show resolved
Hide resolved
docs/4-advanced/05-integration-and-deployment/_samples/fullstack-app/frontend/src/App.tsx
Show resolved
Hide resolved
nakaterm
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
動画もお疲れ様です!
細かいところばかりですがコメントしました!
| ```shell | ||
| $ npm install cors | ||
| $ npm install -D @types/cors | ||
| ``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-
ここは
$が入っているが、「TypeScriptのセットアップをする」のところでは入っていなかったので統一すると良さそうです -
同様の内容をインラインコードで書いてある場所もあるのでどちらかに統一すると良さそうです (理由があって区別しているなら問題ないですが)
npm install expressコマンドとnpm install -D @types/expressコマンドを実行して、Expressとその型定義をインストールします。npm install @prisma/client @prisma/adapter-pg pg dotenvコマンドとnpm install -D prisma @types/pgコマンドを実行して、Prismaを利用するために必要なパッケージをインストールします。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
既存のドキュメントでは、コードブロック内の内容が複数行に渡る場合やコマンドの実行結果を表示する場合には$を先頭に付けており、今回は前者にあたるため$を先頭に付けています。
インラインコードにするか否かについてですが、冗長になることを防ぐため、既存のドキュメントと同様に初出の場合はコードブロックにして既出の場合はインラインコードにしています。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(MTG メモ)
後者については OK です!
前者については、他のところでも同様の問題があったんですね。そしたら今回はこのままにして、またの機会にまとめて対応しましょう!
|  | ||
|  | ||
|
|
||
| <ViewSource url={import.meta.url} path="_samples/fullstack-app" noCodeSandbox /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
コードの編集は「ビルドの設定をする」までで完了するので、この ViewSource は「ビルドの設定をする」の末尾でもいいような気がしました。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
一応、「ビルドの設定をする」の項の末尾というよりも、この節全体の末尾という意味でここに入れたのですが、あまり目立たないんですよね🥺
|
|
||
| // Looking for ways to speed up your queries, or scale easily with your serverless or edge functions? | ||
| // Try Prisma Accelerate: https://pris.ly/cli/accelerate-init | ||
| 1. カレントディレクトリを`backend`ディレクトリに移動し、`npm init`コマンドを実行して`package.json`ファイルを作成します。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
「カレントディレクトリを」って要りますかね?「〇〇ディレクトリに移動し」でいいような気がします。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
また、type を module にすることについて文面でも言及があったほうがいいような気がします。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
「カレントディレクトリを」って要りますかね?「〇〇ディレクトリに移動し」でいいような気がします。
一応ここに合わせた形ではあるのですが、変えます。
| #### Reactのセットアップをする | ||
|
|
||
| ::: | ||
| カレントディレクトリをプロジェクトを格納するディレクトリに移動してから、`npm create vite@latest`コマンドを実行して`frontend`という名前でReactのプロジェクトを作成します。カレントディレクトリを`frontend`ディレクトリに移動してから、`npm install`コマンドを実行して必要なパッケージをインストールします。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同上 (「カレントディレクトリを」)
| provider = "postgresql" | ||
| url = env("DATABASE_URL") | ||
| } | ||
| #### データベースと開発用サーバーを作成する |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Express で動かすバックエンドのサーバーは「Web サーバー」でいいような?
過去のコメント ( #890 (comment) )見ましたが、これ実はコメントつける場所が間違っているんじゃないですかね? 文面見る限り、フロントエンドの Vite のことだけを指しているような気がします (cc: @chelproc )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
私もコメントをつける場所が間違っているだけのような気もしたのですが、あえてバックエンド側も区別してもいいかなとは思い変えてみました。今回は開発環境ではtsxパッケージを用い、本番環境ではtsxパッケージを用いていないので。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
やはり、もとのように「Webサーバー」にします。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 25 out of 51 changed files in this pull request and generated no new comments.
Files not reviewed (2)
- docs/4-advanced/04-react/_samples/todo-database/backend/package-lock.json: Language not supported
- docs/4-advanced/05-integration-and-deployment/_samples/fullstack-app/backend/package-lock.json: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 25 out of 51 changed files in this pull request and generated 1 comment.
Files not reviewed (2)
- docs/4-advanced/04-react/_samples/todo-database/backend/package-lock.json: Language not supported
- docs/4-advanced/05-integration-and-deployment/_samples/fullstack-app/backend/package-lock.json: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
chelproc
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ありがとうございます!
|
|
||
| Viteを用いて構築されたフロントエンドと、Node.jsを用いて構築されたバックエンドを接続する方法について学びましょう。 | ||
|
|
||
| [データベース](/docs/web-servers/database/)の節で作成した掲示板サービスの処理の流れは、次の図のようになっていました。1つのWebサーバーが、フロントエンドで動作するアプリケーションの配信と、バックエンドで動作するアプリケーションの処理の両方を担っています。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
細かいですが
| [データベース](/docs/web-servers/database/)の節で作成した掲示板サービスの処理の流れは、次の図のようになっていました。1つのWebサーバーが、フロントエンドで動作するアプリケーションの配信と、バックエンドで動作するアプリケーションの処理の両方を担っています。 | |
| [データベースの節](/docs/web-servers/database/)で作成した掲示板サービスの処理の流れは、次の図のようになっていました。1つのWebサーバーが、フロントエンドで動作するアプリケーションの配信と、バックエンドで動作するアプリケーションの処理の両方を担っています。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
|
||
| 今回作成する掲示板サービスでは、フロントエンドとバックエンドでそれぞれ別のサーバーを構築します。処理の流れは、次の図のようになります。 | ||
|
|
||
|  |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
コンマ区切り
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
すみません。コメントの内容がわかりませんでした。
「HTML、CSS、JavaScript」と書いたことに関しては、これを日本語文とみなしたからになります。
|
|
||
| 今までの開発環境では、バックエンドとフロントエンドのそれぞれで`npm run dev`コマンドを実行することで、バックエンドの場合には<Term>`tsx`パッケージ</Term>でTypeScriptファイルを実行してWebサーバーを起動し、フロントエンドの場合にはViteの開発用サーバーを起動していました。 | ||
|
|
||
| しかしながら、本番環境では、これとは異なる方法を用いることが一般的です。バックエンドの場合には、TypeScriptファイルをJavaScriptファイルに<Term>トランスパイル</Term>してから、そのJavaScriptファイルを実行してWebサーバーを起動します。フロントエンドの場合には、Viteにより出力されたファイルをRenderで配信します。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
下に表があるので、もっとシンプルに「本番環境では、開発用のツールや設定を取り除いて必要な変換を施し、最適化された最終成果物のみを使用します。このようなプロセスを[[ビルド]]と呼びます。」などとだけ言ってしまい、あとは比較表に任せてしまった方が良いと思います。地味に「ビルド」という言葉は初出ですし、ソフトウェアエンジニアリング全般として重要な用語なので、ちゃんと導入しちゃっても良いかと
|
|
||
| ### ビルドの設定をする | ||
|
|
||
| フロントエンドの場合には、`npm run build`コマンドを実行することで、Viteによるビルド結果が`dist`ディレクトリに格納されるのでした。本番環境では、この`dist`ディレクトリをRenderで配信すればよいです。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
回想形式よりは、対称性もありますし、改めて言ってしまっても良いかなと思います。また、細かいですが「場合には」が適切に使用されていない(フロントエンドはコンディションではなくモノ)気がします👀
フロントエンドのビルドのための設定は、Viteが生成するテンプレートのpackage.json含まれています。npm run buildを実行することで、Viteは最終成果物をdistディレクトリに出力します。...
{
"scripts": {
"build": "vite build"
}
}|
|
||
|  | ||
|
|
||
| 今回作成する掲示板サービスでは、フロントエンドとバックエンドでそれぞれ別のサーバーを構築します。処理の流れは、次の図のようになります。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
やや唐突な感じを受けるので、「フロントエンドとバックエンドの分業が進んだ現代のWebアプリケーションでは、それぞれに別のWebサーバーを用意するのが一般的です。」などと理由を言うと良さそう。
| プロトコル、ドメイン、ポートの組み合わせのことを<Term>**オリジン**</Term>と呼びます。 | ||
|
|
||
| <p> | ||
| <OriginExplanation /> | ||
| </p> | ||
|
|
||
| 異なる<Term>オリジン</Term>のリソースへアクセスすることはブラウザによって制限されることがあります。フロントエンドの開発用サーバーの<Term>オリジン</Term>が`http://localhost:5173`でバックエンドのWebサーバーの<Term>オリジン</Term>が`http://localhost:3000`である場合には、これらは異なる<Term>オリジン</Term>です。そのため、Fetch APIを使用してフロントエンドのアプリケーションからバックエンドのアプリケーションのリソースへアクセスすることはブラウザによって制限されます。 | ||
|
|
||
| {/* prettier-ignore */} | ||
| <Term>**CORS(Cross-Origin Resource Sharing)**</Term>は、このような場合でも異なる<Term>オリジン</Term>のリソースへアクセスすることを可能にする仕組みです。クライアントからのリクエストに対して、サーバーがHTTPレスポンスヘッダにリソースへのアクセスを許可する<Term>オリジン</Term>を示す[`Access-Control-Allow-Origin`ヘッダ](https://developer.mozilla.org/ja/docs/Web/HTTP/Reference/Headers/Access-Control-Allow-Origin)を含めることで、ブラウザはそこで指定された<Term>オリジン</Term>からアクセスすることを許可します。 | ||
|
|
||
| Expressを用いる場合には、[`cors`パッケージ](https://www.npmjs.com/package/cors)を使用することで、HTTPレスポンスヘッダに`Access-Control-Allow-Origin`ヘッダなどを適切に設定することができます。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
オリジンの説明から始まっているので、正確ではあるのですが、CORS自体の説明としてみるとやや理解しづらい気がします。
- 「CORSとは、悪意のあるWebサイトが、利用者のブラウザを利用して本来許可されていないサービスにアクセスし、不正に情報を取得したり操作したりすることを防ぐための、ブラウザのセキュリティ機構です。」などの定義
- 具体的にどう言った場合に制限されのか(ここでオリジンが出てくる)
- 回避する方法
のような構成が良いかと思いました。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ブラウザのセキュリティ機構のことを同一オリジンポリシーと呼び、これを緩和する仕組みをCORSと呼ぶと私は理解しています。
そのため、オリジンを説明して、オリジンの説明をもとに同一オリジンポリシーを説明して、同一オリジンポリシーの説明をもとにCORSの説明をするという流れになっています。ただ、同一オリジンポリシーという用語を導入しないようにしているため、少し具体性に欠けるところはあるようにも思います。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ミーティングの内容の結果、具体的にフロントエンドとバックエンドが別のサーバーである時には、ブラウザでブロックされることがあり、それを緩和するのがCORSです。のように入り、その後に詳しく説明するのがよさそうという話をしました。
| Viteは起動時に`.env`ファイルの内容を読み込みます。 | ||
|
|
||
| Viteは、[`VITE_`で始まる<Term>環境変数</Term>を、アプリケーション内で`import.meta.env`オブジェクトのプロパティとして利用](https://ja.vite.dev/guide/env-and-mode.html#env-variables)できるようにします。例えば、`VITE_API_ENDPOINT`という<Term>環境変数</Term>の値は、`import.meta.env.VITE_API_ENDPOINT`と記述することで利用できます。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
第1文と第2文がぶつ切りに感じるので、第2文を述べたあと、「また、Viteは、.envファイルに記載された内容を、環境変数と同様に扱います(環境変数として読み込みます)。」の順番で説明するのはどうでしょう?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
私もそのように書いたほうが自然かなとは思っており、以前はそのように書いていたのですが、現在のように書いたほうが自然だという意見があったため変更した次第になります。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
次のような形でしょうか。
Viteは、
VITE_で始まる環境変数を、アプリケーション内でimport.meta.envオブジェクトのプロパティとして利用できるようにします。例えば、VITE_API_ENDPOINTという環境変数の値は、import.meta.env.VITE_API_ENDPOINTと記述することで利用できます。
なお、Viteは起動時に
.envファイルに記述された環境変数を読み込みます。
|
|
||
| フロントエンドの場合には、`npm run build`コマンドを実行することで、Viteによるビルド結果が`dist`ディレクトリに格納されるのでした。本番環境では、この`dist`ディレクトリをRenderで配信すればよいです。 | ||
|
|
||
| 次に、バックエンドのTypeScriptファイルを<Term>トランスパイル</Term>するための設定を行いましょう。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
このレイヤーの説明であれば基本的に言葉は「ビルド」に統一した方が良いかと思います。「トランスパイル」はややJSのエコシステムに引っ張られている感じがします、prisma generateもありますしね。
この節で書く内容の概略と節構成は #886 を参照してください。
「ここに動画を埋め込む」と記載されているところに、今後動画を掲載します。動画の掲載以外については現在すべて完了しています。
Prismaの使用法については、最新のPrisma 7.1.0の使用法に合わせて記述しています。現在のut.code(); LearnでのPrismaの使用法はPrisma 6.18以前の使用法であることに注意してください。こちらについての情報は #892 にまとめているので、参照してください。