|
| 1 | +# Cors Proxy |
| 2 | + |
| 3 | +MagicMirror² contains an internal cors proxy which is useful for some modules. |
| 4 | + |
| 5 | +Since MagicMirror² versions greater `v2.35.0` the cors proxy is disabled by |
| 6 | +default due to security reasons. |
| 7 | + |
| 8 | +## What is a cors proxy? |
| 9 | + |
| 10 | +There are some good articles online, e.g. |
| 11 | +[What are CORS proxies, and when are they safe?](https://httptoolkit.com/blog/cors-proxies/). |
| 12 | + |
| 13 | +## Why do we need a cors proxy for MagicMirror²? |
| 14 | + |
| 15 | +We ran into cors problems with some modules which make api requests to external |
| 16 | +websites from inside the browser. |
| 17 | + |
| 18 | +Examples are |
| 19 | + |
| 20 | +- some news url's when using the default newsfeed module |
| 21 | +- 3rd-party modules (e.g. weather api's) |
| 22 | +- ... |
| 23 | + |
| 24 | +To get such url's working we can use the internal cors proxy. Instead using the |
| 25 | +original url `https://example.com` in the module configuration we use |
| 26 | +`/cors?url=https://example.com`. With this the request doesn't go directly from |
| 27 | +the browser to the external url but to the MagicMirror² Server which makes the |
| 28 | +call to the external url and sends the answer back to the browser. |
| 29 | + |
| 30 | +## Setup cors proxy |
| 31 | + |
| 32 | +You have to enable the cors proxy in `config.js`. |
| 33 | + |
| 34 | +::: warning NOTE |
| 35 | + |
| 36 | +We offer no guarantee that the use of the cors proxy is safe in all setups. We |
| 37 | +investigated in security and protecting against misuse, but use at your own |
| 38 | +risk. |
| 39 | + |
| 40 | +::: |
| 41 | + |
| 42 | +You can us 2 setup variants. |
| 43 | + |
| 44 | +### Cors allow all |
| 45 | + |
| 46 | +This opens cors to all url's. You should only use this if your MagicMirror² is |
| 47 | +not reachable from outside your network: |
| 48 | + |
| 49 | +```js |
| 50 | + cors: "allowAll", |
| 51 | +``` |
| 52 | + |
| 53 | +### Cors allow whitelist |
| 54 | + |
| 55 | +This is the safest variant. You have to list all domains which are allowed to |
| 56 | +make cors requests: |
| 57 | + |
| 58 | +```js |
| 59 | + cors: "allowWhitelist", |
| 60 | + corsDomainWhitelist: ["example.com", "api.mapbox.com"], |
| 61 | +``` |
0 commit comments