angularjscorscross-domainlagomhttp-options-method

ERROR Angularjs + Lagom Framework


OPTIONS http://localhost:9000/api/chat/ 404 (Not Found) XMLHttpRequest cannot load http://localhost:9000/api/chat/. Response for preflight has invalid HTTP status code 404


Solution

  • https://www.playframework.com/documentation/2.5.x/CorsFilter has details on enabling CORS for Play (which is Lagom is built on). To handle the OPTIONS you may need to do something like:

    .withAutoAcl(true)
    .withServiceAcls(
      ServiceAcl.methodAndPath(Method.OPTIONS, "/foo")
    )
    

    https://groups.google.com/forum/#!msg/lagom-framework/dtYN_1Ds4SQ/gT-BGPuCAQAJ is a lagom-framework list discussion thread with more details.

    https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS#Preflighted_requests has an explanation of why your browser is sending an OPTIONS request to begin with.


    The metadata for the current exact maven artifact which provides CORS for Play is this:

    <metadata>
      <groupId>com.typesafe.play</groupId>
      <artifactId>filters-helpers_2.12</artifactId>
      <versioning>
        <latest>2.6.0-M2</latest>
        <release>2.6.0-M2</release>
        <versions>
          <version>2.6.0-M1</version>
          <version>2.6.0-M2</version>
        </versions>
        <lastUpdated>20170310220437</lastUpdated>
      </versioning>
    </metadata>