Commit 841ae047 authored by Chris Castle's avatar Chris Castle Committed by Dan Abramov
Browse files

Clarify proxy instructions in generated app README (#537)

* Clarify proxy instructions in generated app README

* Add backticks to format text/html as code
parent d6e8939a
No related merge requests found
Showing with 2 additions and 2 deletions
+2 -2
...@@ -513,7 +513,7 @@ To tell the development server to proxy any unknown requests to your API server ...@@ -513,7 +513,7 @@ To tell the development server to proxy any unknown requests to your API server
"proxy": "http://localhost:4000", "proxy": "http://localhost:4000",
``` ```
This way, when you `fetch('/api/todos')` in development, the development server will recognize that it’s not a static asset, and will proxy your request to `http://localhost:4000/api/todos` as a fallback. This way, when you `fetch('/api/todos')` in development, the development server will recognize that it’s not a static asset, and will proxy your request to `http://localhost:4000/api/todos` as a fallback. The development server will only attempt to send requests without a `text/html` accept header to the proxy.
Conveniently, this avoids [CORS issues](http://stackoverflow.com/questions/21854516/understanding-ajax-cors-and-security-considerations) and error messages like this in development: Conveniently, this avoids [CORS issues](http://stackoverflow.com/questions/21854516/understanding-ajax-cors-and-security-considerations) and error messages like this in development:
...@@ -521,7 +521,7 @@ Conveniently, this avoids [CORS issues](http://stackoverflow.com/questions/21854 ...@@ -521,7 +521,7 @@ Conveniently, this avoids [CORS issues](http://stackoverflow.com/questions/21854
Fetch API cannot load http://localhost:4000/api/todos. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled. Fetch API cannot load http://localhost:4000/api/todos. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
``` ```
Keep in mind that `proxy` only has effect in development (with `npm start`), and it is up to you to ensure that URLs like `/api/todos` point to the right thing in production. You don’t have to use the `/api` prefix. Any unrecognized request will be redirected to the specified `proxy`. Keep in mind that `proxy` only has effect in development (with `npm start`), and it is up to you to ensure that URLs like `/api/todos` point to the right thing in production. You don’t have to use the `/api` prefix. Any unrecognized request without a `text/html` accept header will be redirected to the specified `proxy`.
Currently the `proxy` option only handles HTTP requests, and it won’t proxy WebSocket connections. Currently the `proxy` option only handles HTTP requests, and it won’t proxy WebSocket connections.
If the `proxy` option is **not** flexible enough for you, alternatively you can: If the `proxy` option is **not** flexible enough for you, alternatively you can:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment