| 1 |
# JavaScript Frontends |
| 2 |
|
| 3 |
Examples in this directory are intended to provide basic working frontend JavaScript, compatible |
| 4 |
with the API backend examples available in the [`examples/api-backends`](../api-backends). |
| 5 |
|
| 6 |
## CSRF and CORS compatibility |
| 7 |
|
| 8 |
In order to be compatible with a CSRF-protected backend, frontend clients must: |
| 9 |
|
| 10 |
1. Be served from a domain allowed by the backend's CORS Allowed Origins configuration. |
| 11 |
1. `http://localhost*` for the backend examples provided |
| 12 |
2. An example server to serve the HTML and JavaScript for the frontend examples from localhost is included in |
| 13 |
[`examples/javascript-frontends/example-frontend-server`](../javascript-frontends/example-frontend-server) |
| 14 |
3. Use the HTTP headers expected by the backend to send and receive CSRF Tokens. |
| 15 |
The backends configure this as the Gorilla `csrf.RequestHeader`, |
| 16 |
as well as the CORS Allowed Headers and Exposed Headers. |
| 17 |
1. `X-CSRF-Token` for the backend examples provided |
| 18 |
2. Note that some JavaScript HTTP clients automatically lowercase all received headers, |
| 19 |
so the values must be accessed with the key `"x-csrf-token"` in the frontend code. |