Ground Sunlight

Windowsで作る - PHPプログラミングの開発環境

ユーザ用ツール

サイト用ツール


slim:4:cookbook

差分

このページの2つのバージョン間の差分を表示します。

この比較画面にリンクする

両方とも前のリビジョン 前のリビジョン
次のリビジョン
前のリビジョン
最新のリビジョン 両方とも次のリビジョン
slim:4:cookbook [2020/10/13 17:26]
y2sunlight [Retrieving Current Route]
slim:4:cookbook [2020/10/13 21:31]
y2sunlight [Access-Control-Allow-Credentials]
行 24: 行 24:
 ===== ルートパターンの末尾のスラッシュ(/) ===== ===== ルートパターンの末尾のスラッシュ(/) =====
  
-Slim treats a URL pattern with a trailing slash as different to one without. That is, ''/user'' and ''/user/'' are different and so can have different callbacks attached. +Slimは、末尾にスラッシュがあるURLパターンを、いものとは異なるものとして扱います。つまり、''/user'' と ''/user/'' は異なるので、異なるコールバックをアタッチできます。
- +
-Slimは、末尾にスラッシュがあるURLパターンを、いものとは異なるものとして扱います。 つまり、''/user'' と ''/user/'' は異なるため、異なるコールバックをアタッチできます。+
  
 For GET requests a permanent redirect is fine, but for other request methods like POST or PUT the browser will send the second request with the GET method. To avoid this you simply need to remove the trailing slash and pass the manipulated url to the next middleware. For GET requests a permanent redirect is fine, but for other request methods like POST or PUT the browser will send the second request with the GET method. To avoid this you simply need to remove the trailing slash and pass the manipulated url to the next middleware.
  
-GETリクエストの場合、永続的なリダイレクトは問題ありませんが、POSTやPUTなどの他のリクエストメソッドの場合、ブラウザはGETメソッドを使用して2番目のリクエストを送信します。 これを回避するには、末尾のスラッシュを削除し、操作されたURLを次のミドルウェアに渡す必要があります。 +GETリクエストの場合、パーマネント(permanent)リダイレクトは問題ありませんが、POSTやPUTなどの他のリクエストメソッドの場合、ブラウザはGETメソッドを使用して2番目のリクエストを送信します。これを回避するには、単に、末尾のスラッシュを削除し、操作されたURLを次のミドルウェアに渡す必要があります。
- +
-If you want to redirect/rewrite all URLs that end in a ''/'' to the non-trailing ''/'' equivalent, then you can add this middleware:+
  
-''/'' で終わるすべてのURLを、末尾以外の ''/'' に相当するものにリダイレクト/書き換える場合、次のミドルウェアを追加できます。+''/'' で終わるすべてのURLを、末尾以外の ''/'' に相当するものにリダイレクトまたはリライトする場合、次のミドルウェアを追加できます。
  
 <code php> <code php>
行 73: 行 69:
 </code> </code>
  
-Alternatively, consider [[https://github.com/middlewares/trailing-slash|middlewares/trailing-slash]] middleware which also allows you to force a trailing slash to be appended to all URLs: +あるいは、[[https://github.com/middlewares/trailing-slash|middlewares/trailing-slash]] ミドルウェアを検討してください。これにより、すべてのURLに末尾のスラッシュを強制的に追加することもできます。
- +
-または、[[https://github.com/middlewares/trailing-slash|middlewares/trailing-slash]] ミドルウェアを検討してください。これにより、すべてのURLに末尾のスラッシュを強制的に追加することもできます。+
  
 <code php> <code php>
行 138: 行 132:
 \\ \\
  
-===== Setting up CORS =====+===== CORSの設定 =====
  
-CORS - Cross origin resource sharing+CORS - クロス オリジンリソース シェアリング(オリジン間リソース共有)
  
-A good flowchart for implementing CORS support Reference:+  * CORSサポートを実装するための適切なフローチャートリファレンス: \\ [[https://www.html5rocks.com/static/images/cors_server_flowchart.png|CORSサーバーのフローチャート]] 
 +  * CORSサポートはここでテストできます:[[http://www.test-cors.org/]] 
 +  * ここで仕様を読むことができます:[[https://www.w3.org/TR/cors/]]
  
-CORS server flowchart+> 参考:https://developer.mozilla.org/ja/docs/Glossary/CORS 
 +==== シンプル ソリューション ====
  
-You can test your CORS Support here: http://www.test-cors.org/+単純なCORSリクエストの場合、サーバーはレスポンスに次のヘッダーを追加するだけで済みます。
  
-You can read the specification here: https://www.w3.org/TR/cors/ +<code>
- +
-CORS-クロスオリジンリソースシェアリング +
- +
-CORSサポートを実装するための適切なフローチャートリファレンス: +
- +
-CORSサーバーのフローチャート +
- +
-CORSサポートはここでテストできます:http://www.test-cors.org/ +
- +
-ここで仕様を読むことができます:https://www.w3.org/TR/cors/ +
-==== The simple solution ==== +
- +
-For simple CORS requests, the server only needs to add the following header to its response: +
- +
-単純なCORSリクエストの場合、サーバーは応答に次のヘッダーを追加するだけで済みます。 +
- +
-<code php>+
 Access-Control-Allow-Origin: <domain>, ...  Access-Control-Allow-Origin: <domain>, ... 
 </code> </code>
行 171: 行 151:
 The following code should enable lazy CORS. The following code should enable lazy CORS.
  
-次のコードは、レイジーCORSを有効にする必要があります。+次のコードは、Lazy CORS を有効にする必要があります。
  
 <code php> <code php>
行 186: 行 166:
 }); });
 </code> </code>
- 
-Add the following route as the last route: 
  
 最後のルートとして次のルートを追加します: 最後のルートとして次のルートを追加します:
行 207: 行 185:
  
 ==== Access-Control-Allow-Methods ==== ==== Access-Control-Allow-Methods ====
- 
-The following middleware can be used to query Slim’s router and get a list of methods a particular pattern implements. 
- 
-Here is a complete example application: 
  
 次のミドルウェアを使用して、Slimのルーターにクエリを実行し、特定のパターンが実装するメソッドのリストを取得できます。 次のミドルウェアを使用して、Slimのルーターにクエリを実行し、特定のパターンが実装するメソッドのリストを取得できます。
行 327: 行 301:
 ==== Access-Control-Allow-Credentials ==== ==== Access-Control-Allow-Credentials ====
  
-If the request contains credentials (cookies, authorization headers or TLS client certificates), you might need to add an ''Access-Control-Allow-Credentials'' header to the response object. +リクエストに資格情報(Cookie、承認ヘッダー、またはTLSクライアント証明書)が含まれている場合は、レスポンスオブジェクトに ''Access-Control-Allow-Credentials'' ヘッダーを追加する必要がある場合があります。
- +
-要求に資格情報(Cookie、承認ヘッダー、またはTLSクライアント証明書)が含まれている場合は、応答オブジェクトに ''Access-Control-Allow-Credentials'' ヘッダーを追加する必要がある場合があります。+
  
 <code php> <code php>
slim/4/cookbook.txt · 最終更新: 2020/10/13 21:59 by y2sunlight