Hey :wave:, I'm facing CORS issues using Ktor clie...
# ktor
m
Hey 👋, I'm facing CORS issues using Ktor client for Kotlin JS. I'm know it's not an issue in ktor side, but I'm trying to find a solution.
Access to fetch at '<https://myserver/api/v1/csrf>' from origin '<http://localhost:8080>' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
I want to know if it's possible to use a reverse proxy in KotlinJs client. I tried to setup a proxy, in the engine setup, but it's not supported for JS. Basically, I need to do something like this (this is how I solve my issue using react) . Do you know how can do something similar using ktor? Or do you know some alternative? Thanks!
Maybe there is a better alternative
s
If its only for development then you can also disable it in the browser with addons such as https://chrome.google.com/webstore/detail/cors-unblock/lfhmikememgdcahcdlaciloancbhjino
🙌 1
I do not have experience with it myself but others I know of use something like this
m
Thanks! I used this extension: https://www.moesif.com/ But it didn't work in all endponts, I'm not sure why
a
@mirland there is no built-in feature in the Ktor client to start a reverse proxy server. As one more alternative solution, you can configure Nginx as a reverse proxy where necessary CORS headers are sent with each response.
Or you can use Ktor server as a reverse proxy.
m
Cool, I thought the same response, but I wanted just to confirm it! thanks!
l
I ran into a similar problem and it turned out that something (Google Cloud API Gateway) along the path from client to Ktor was blocking the options method.
849 Views