Enabling CORS in Quarkus

Cross Origin Resource Sharing(CORS) is a mechanism, that allows restricted resource access from a different domain other than the domain from which the resource is being served. By default CORS is disabled in the Quarkus application. Enabling CORS in Quarkus application allows external domain to access the restricted application resources.

In this article, we will learn how to enable the Cross Origin Resource Sharing(CORS) in the Quarkus application.

Enabling CORS in Quarkus

Quarkus provides below configuration properties, that can be leveraged to enable or configure the CORS settings.

quarkus.http.cors=true
quarkus.http.cors.origins=http://example.com

Here, setting the quarkus.http.cors property value to true enables the CORS for our Quarkus application.

We can also specify the CORS origin domains with the help of the configuration property quarkus.http.cors.origins

We can also use other additional properties like allowed HTTP methods, and HTTP request headers, etc as shown below.

quarkus.http.cors.methods=GET
quarkus.http.cors.headers=accept,authorization,content-type

Now let us test the CORS setting by accessing the REST endpoint with the help of CURL.

enable cors quarkus

Conclusion

In this post, we learned how simple it is to enable CORS in a Quarkus application with the help of configuration properties.

Enabling CORS in Quarkus

Leave a Reply

Scroll to top

Discover more from ASB Notebook

Subscribe now to keep reading and get access to the full archive.

Continue reading