Skip to content
Advertisement

CORS issue / akka-http-cors / No ‘Access-Control-Allow-Origin’ header is present on the requested resource in Scala/Java

How do I implement akka-http-cors correctly to be able to allow access from any origin (domain, in my case localhost:3000) to a Https Server (Scala/Akka)?

Based on the akka-http-cors documentation should defaultSettings do the job, but I am still doing something wrong:

JavaScript

JavaScript

Google Chrome Error:

JavaScript

Firefox Error:

JavaScript

akka-http-core: https://github.com/lomigmegard/akka-http-cors#configuration

Any help is highly appreciated!

Advertisement

Answer

The problem in my case was that I haven’t done Marshalling in the right way, thereby it crashed in following line:

JavaScript

Surprisingly to me, that the error is than labeled as CORS error.

I solved it by checking the Akka HTTP JSON Support manual: https://doc.akka.io/docs/akka-http/current/common/json-support.html

It now works for me in my case by having this upfront:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement