title: How to allow CORS in router functions?
body: <p>I'm building a web application rest controller using Spring 5 router functions to map requests.</p>
  
  <pre class="lang-java prettyprint-override"><code>@RestController
  public class AdminRest {
  
  public RouterFunction&lt;ServerResponse&gt; route() {
      return RouterFunctions
              .route(RequestPredicates.GET("/admin/organizations"), this::getOrganizations);
  }
  }
  </code></pre>
  
  <p>Having Angular 4 project acts as a consumer for the rest controller.</p>
  
  <pre><code>public getOrganizations(): Observable&lt;OrganizationsList&gt; {
  return this.http.get(this.getOrganizationsUrl)
    .map((res: Response) =&gt; res.json())
    .catch((error: any) =&gt; Observable.throw(error.json().error || 'Server error'));
   }
  </code></pre>
  
  <p>Which return this error </p>
  
  <blockquote>
    <p>XMLHttpRequest cannot load <a href="http://ip:port/admin/organizations" rel="nofollow noreferrer">http://ip:port/admin/organizations</a>. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin '<a href="http://localhost:3000" rel="nofollow noreferrer">http://localhost:3000</a>' is therefore not allowed access. The response had HTTP status code 500. }</p>
  </blockquote>
  
  <p>How can I allow CORS in Spring 5 router function? </p>