title: How do I enable CORS in Giraffe?
body: <p>I am unable to successfully perform a Post operation using the Giraffe framework on the server with an Elm client sending the request.</p>
  
  <p>I receive the following message when attempting to test an http request:</p>
  
  <blockquote>
    <p>info: Microsoft.AspNetCore.Hosting.Internal.WebHost<a href="https://github.com/bizmonger/Nikeza/blob/master/Server/Nikeza.Server/Routes.fs" rel="nofollow noreferrer">1</a></p>
  
  <pre><code>  Request starting HTTP/1.1 OPTIONS http://localhost:5000/register  0 
  </code></pre>
    
    <p>Microsoft.AspNetCore.Hosting.Internal.WebHost:Information: Request</p>
    
    <p>starting HTTP/1.1 OPTIONS <a href="http://localhost:5000/register" rel="nofollow noreferrer">http://localhost:5000/register</a>  0 dbug:
    Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware<a href="https://github.com/bizmonger/Nikeza/blob/master/Server/Nikeza.Server/Routes.fs" rel="nofollow noreferrer">1</a></p>
  
  <pre><code>  OPTIONS requests are not supported
  </code></pre>
  </blockquote>
  
  <p>The service implementation is the following:</p>
  
  <pre><code>let private registrationHandler = 
      fun(context: HttpContext) -&gt; 
          async {
              let! data = context.BindJson&lt;RegistrationRequest&gt;()
              match register data with
                | Success profile -&gt; return! json profile context
                | Failure         -&gt; return! (setStatusCode 400 &gt;=&gt; json "registration failed") context
          }
  </code></pre>
  
  <p>I then attempted the following and observed the same result:</p>
  
  <pre><code>let private registrationHandler = 
      fun(context: HttpContext) -&gt; 
          async {
              return! text "hello world" context
          }
  </code></pre>
  
  <p><strong>Appendix:</strong></p>
  
  <pre><code>    POST &gt;=&gt; 
          choose [
              route "/register" &gt;=&gt; registrationHandler
          ]
  </code></pre>
  
  <p>The source file can be found <a href="https://github.com/bizmonger/Nikeza/blob/master/Server/Nikeza.Server/Routes.fs" rel="nofollow noreferrer">here</a>.</p>
  
  <p><a href="https://github.com/evancz/elm-http/issues/45" rel="nofollow noreferrer">Elm and CORS</a></p>
  
  <p><a href="https://docs.microsoft.com/en-us/aspnet/web-api/overview/security/enabling-cross-origin-requests-in-web-api" rel="nofollow noreferrer">WebAPI enable Cors</a></p>
  
  <p>Here's a <a href="https://github.com/dustinmoris/Giraffe/commit/ec11a12d5ac69f8d9c911f7b4b42c3188a18e975" rel="nofollow noreferrer">Giraffe sample</a> that shows the code for supporting Cors.</p>