Hey everyone, I am having the following issue when...
# multiplatform
b
Hey everyone, I am having the following issue when trying to call a Firebase cloud function from the browser:
Access to fetch at 'https://{cloud_functuion_url}/' from origin '<http://localhost:8080>' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
Could someone advice on how to fix this ? Do I need to enable CORS on the firebase side (sorry I dont have much experience with this) ? This is how I initialise the ktor client in DI:
Copy code
val networkModule = module {
    single {
        HttpClient {
            install(ContentNegotiation) {
                json(Json {
                    prettyPrint = true
                    isLenient = true
                    ignoreUnknownKeys = true
                })
            }
        }
    }
}
The project is kotlin multiplatform project supporting android, iOS and web. The ktor function is only triggered via web though but the code lives in the
common
directory. Will appreciate any help on this - been stuck up on days with this!!
c
Simple google search would have revealed this https://firebase.google.com/docs/functions/http-events?gen=2nd#configuring_cors_cross-origin_resource_sharing Didn’t need to block you for days 😅
And for background why it’s needed https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS