Anyone know of a way to proxy gradle's webserver s...
# compose-web
e
Anyone know of a way to proxy gradle's webserver so I can do XMLHttpRequest from the app? The kotlin/gradle/java/etc equivalent of this Node.js code:
const config = {
async rewrites() {
return [
{
source: '/api/:path*',
destination: '<http://localhost:4000/:path*>' // Proxy to Backend
}
]
}
};
c
gradle does not come with a webserver. compose is started with with the https://webpack.js.org/configuration/dev-server/ that you can configure as in the description
just put a file with the config in as descirped in here https://kotlinlang.org/docs/js-project-setup.html#webpack-configuration-file
e
The only webpack file is in proj/build/js/packages/composeApp/webpack.config.js, it seems to get overwritten if I modify it directly when I start the gradle task to server the devserver
c
If you want to make further adjustments to the webpack configuration, place your additional configuration files inside a directory called
webpack.config.d
in the root of your project.
When building your project, all
.js
configuration files will automatically be merged into the
build/js/packages/projectName/webpack.config.js
file.
from the link I posted above 😉
e
Thanks, im on a single monitor today. I'll try that.
😅 1
c
If that defines your reading skills - good luck with programming 😅
e
Really? If I search for webpack.config.d on that link I dont find anything.
e
cheers
this doesnt seem to be doing the trick:`cat webpack.config.d/webpack.config.js`
config.module.rules.push({
proxy: [
{
context: ['/api'],
target: '<http://localhost:3000>',
},
],
});
its not getting merged into the file when i run ./gradlew composeAppwasmJsBrowserDevelopmentRun
c
1. the folder is a direct child of
composeApp/
? 2. you do not want to change the
config.module.rules
but the
config.devServer
see the second link I posted in the first response.
e
It says in the root of the project. I will try it in composeapp and update to config.devserver
c
your gradle project is
composeApp
😉
here’s my config file
Copy code
(function (config) {
    config.devServer = {
        ...config.devServer,
        "historyApiFallback": true,
        proxy: [{
            context: ['/api'],
            target: '<http://localhost:8089>',
        }],
    };
})(config);
e
That worked!! Thank you!!
👍🏻 1