quarkus: CORS with Ajax is not working well.

Calling REST resources using Ajax is not working fine I am trying to call a service sides on my localhost:8080/person (POST) through VueJS app on my localhost:8084 but it is not working. I tried to enable CORS config. in application.properties with the below :

quarkus.http.cors=true quarkus.http.cors.origins=http://localhost:8084 quarkus.http.cors.headers=accept, authorization, content-type, x-requested-with quarkus.http.cors.methods=GET, PUT, POST

Expected behavior It should work fine and be able to call my resource.

Actual behavior Browser logs error :

Access to XMLHttpRequest at ‘http://localhost:8080/person’ from origin ‘null’ has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.

Even it is not reaching to my ContainerRequestFilter code.

To Reproduce Steps to reproduce the behavior:

  1. Any REST resource. in my case I used POST method with application/json.
  2. Try to call it from different app (port) using Ajax library (jQuery or Axiom).

Configuration

> quarkus.http.cors=true
> quarkus.http.cors.origins=http://localhost:8084
> quarkus.http.cors.headers=accept, authorization, content-type, x-requested-with
> quarkus.http.cors.methods=GET, PUT, POST

Environment (please complete the following information):

  • Output of uname -a or ver: Darwin SDG0268LMAC 18.6.0 Darwin Kernel Version 18.6.0: Thu Apr 25 23:16:27 PDT 2019; root:xnu-4903.261.4~2/RELEASE_X86_64 x86_64
  • Output of java -version: OpenJDK Runtime Environment Corretto-8.202.08.2 (build 1.8.0_202-b08)
  • GraalVM version (if different from Java): graalvm-ce-19.0.2
  • Quarkus version or git rev: 0.18.0

Additional context Event if CORS is disabled same issue is produced.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 4
  • Comments: 29 (12 by maintainers)

Most upvoted comments

Dears, I’ve generated the issue again with latest version. I’ve created two repositories for this. One for Quarkus as the backend APIs and the other one is the VueJS as front end.

Quarkus : https://github.com/iabughosh/microprofile-health VueJS : https://github.com/iabughosh/VueJs

I will do some debugging from my end too.

Regards.

I have same issue…i have tried all above ways.but still not work.issue is still there of cors

Ah, so it’s on the OpenAPI endpoint, I didn’t try that. I’ll check tomorrow, thanks for the info.