CORS For The WordPress REST API

If we need to permit CORS for the WordPress REST API, we should add code like following.
https://github.com/WP-API/WP-API/issues/2844#issuecomment-275930957
One more way:
add_filter( 'http_origin', function() {
return "https://example.com";
} );