Timo Drick
05/15/2024, 12:37 PMCORS header 'Access-Control-Allow-Origin' missing
. So my question is how can i add this missing header in the dev server which is running when i execute the gradle task: wasmJsBrowserDevelopmentRun
Is it possible to configure this in the gradle file?
kotlin {
@OptIn(ExperimentalWasmDsl::class)
wasmJs {
moduleName = "composeApp"
browser {
commonWebpackConfig {
outputFileName = "composeApp.js"
devServer = (devServer ?: KotlinWebpackConfig.DevServer()).apply {
static = (static ?: mutableListOf()).apply {
// Serve sources to debug inside browser
add(project.projectDir.path)
}
}
}
}
binaries.executable()
}
//...
Robert Jaros
05/15/2024, 12:40 PMTimo Drick
05/15/2024, 12:47 PMRobert Jaros
05/15/2024, 12:52 PMTimo Drick
05/15/2024, 12:56 PMRobert Jaros
05/15/2024, 12:58 PMTimo Drick
05/15/2024, 12:59 PMTimo Drick
05/15/2024, 12:59 PMCasey Brooks
05/15/2024, 1:34 PM<http://app.example.com|app.example.com>
, and wants to access <http://otherapp.com|otherapp.com>
which doesn’t support CORS. What you need to do is run your own API server (either at <http://app.example.com/api|app.example.com/api>
, or at <http://api.example.com|api.example.com>
but configured with CORS correctly). <http://app.example.com|app.example.com>
makes a request to your own API server, which then makes the call to <http://otherapp.com|otherapp.com>
and returns the response.
Note that this is a lot of extra work having to proxy everything through your own server, but it can also be a good practice in general. It allows you to store the API keys for <http://otherapp.com|otherapp.com>
on your server, rather than having them available in the JS bundle or asking the user to log in to <http://otherapp.com|otherapp.com>
for your app. It also allows you the ability to cache the responses, which improves performance for your app and also reduces the load on the other app.Casey Brooks
05/15/2024, 1:36 PM