In kobweb project I have two modules: jsMain where I have frontend in kobweb.compose, and jvmMain where I have backend with API access point.
In jvmMain:
import com.varabyte.kobweb.api.Api
@Api(routeOverride = "getSettings")
fun getSettings(context: ApiContext) {
val result = getCompanySettings()
context.res.setBodyText(result)
}
fun getCompanySettings():String{
AppUtils.initializeFirebase()
try {
val future = com.google.firebase.cloud.FirestoreClient
.getFirestore()
.options.service
.collection(AppConstants.FB_COMPANIES_COLLECTION)
.document("test1")
.get()
val snapshot: DocumentSnapshot = future.get()
if (snapshot.exists()) {
return snapshot.getString("settings").toString()
} else {
return "Snapshot not exists"
}
} catch (e: Exception) {
return "Error: ${e.message}"
}
}
If I test method getCompanySettings()
(i.e. starting from main()
), everything works fine and I receive data from Firestore. If I test @Api getSettings
in localhost with some String as response – also everything OK. I get the String in my WWW, but if try to get response from Firestore in my WWW, than I receive an error:
Error: java.lang.IllegalArgumentException: Address types of NameResolver ‘unix’ for ‘firestore.googleapis.com:443’ not supported by transport
How to solve it?