}

Exum: How to configure Cross-Origin headers

Created:

The problem

If you want to use Exonum REST API directly from other server you will get the following error:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource

if you want more about CORS, click here

Solution

You can fix it with:

use iron::headers::{AccessControlAllowOrigin};

In the wire method you should use:

let ok_res = self_.ok_response(&serde_json::to_value(&json).unwrap());
let mut res = ok_res.unwrap();
res.headers.set(AccessControlAllowOrigin::Any);
Ok(res)

Remeber that CORS is a security feature, allowing any could be a bad idea. But setting the headers AccessControlAllowOrigin should fix this issue.

Use this configuration carefully.