= CORS Extension

:Notice: Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at. http://www.apache.org/licenses/LICENSE-2.0 . Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR  CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.


This extension configures specified CORS headers for the endpoints exposed by the xref:vro:ROOT:about.adoc[].

To learn more about CORS, see for example link:https://www.moesif.com/blog/technical/cors/Authoritative-Guide-to-CORS-Cross-Origin-Resource-Sharing-for-REST-APIs/#how-is-origin-definedhttps://www.moesif.com/blog/technical/cors/Authoritative-Guide-to-CORS-Cross-Origin-Resource-Sharing-for-REST-APIs/#how-is-origin-defined[this blog post at www.moesif.com]


== Setup

=== Dependency Management

In your application's top level `pom.xml`, add a dependency for this module's own bill of materials (BOM):

[source,xml,subs="attributes+"]
.pom.xml
----
<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.apache.causeway.extensions</groupId>
            <artifactId>causeway-extensions-cors</artifactId>
            <scope>import</scope>
            <type>pom</type>
            <version>{page-causewayrel}</version>
        </dependency>
    </dependencies>
</dependencyManagement>
----


=== Dependencies / Imports

In the webapp module of your application, add the following dependency:

[source,xml]
.pom.xml
----
<dependency>
    <groupId>org.apache.causeway.extensions</groupId>
    <artifactId>causeway-extensions-cors-impl</artifactId>
</dependency>
----

In your application's xref:userguide::modules.adoc#appmanifest[App Manifest], import the extension's implementation module:

[source,java]
.AppManifest.java
----
@Configuration
@Import({
        CausewayModuleExtCors.class,
        ...
})
public class AppManifest {
}
----


== Configuration

Update the configuration properties:

[source,yml]
.application.yml
----
causeway:
    extensions:
        cors:
            allow-credentials: ...  # <.>
            allow-headers: ...      # <.>
            allow-methods: ...      # <.>
            allow-origins: ...      # <.>
            exposed-headers: ...    # <.>
----
<.> xref:refguide:config:sections/causeway.extensions.adoc#causeway.extensions.cors.allow-credentials[causeway.extensions.cors.allow-credentials]
<.> xref:refguide:config:sections/causeway.extensions.adoc#causeway.extensions.cors.allowed-headers[causeway.extensions.cors.allow-headers]
<.> xref:refguide:config:sections/causeway.extensions.adoc#causeway.extensions.cors.allowed-methods[causeway.extensions.cors.allow-methods]
<.> xref:refguide:config:sections/causeway.extensions.adoc#causeway.extensions.cors.allowed-origins[causeway.extensions.cors.allow-origins]
<.> xref:refguide:config:sections/causeway.extensions.adoc#causeway.extensions.cors.exposed-headers[causeway.extensions.cors.exposed-headers]
