How can I run kotlin/js in secure context? (HTTPS)...
# javascript
m
How can I run kotlin/js in secure context? (HTTPS). I am using browser configuration (resolved in 🧵)
Here is webpack config that i placed in
webpack.config.d
folder to run in secure context:
Copy code
function setupDevServer(callback) {
    const devCerts = require('office-addin-dev-certs');
    devCerts.getHttpsServerOptions()
        .then(httpsOptions => {
            const serverOptions = {
                headers: {
                    "Access-Control-Allow-Origin": "*",
                },
                server: {
                    type: 'https',
                    options: {
                        ca: <http://httpsOptions.ca|httpsOptions.ca>,
                        key: httpsOptions.key,
                        cert: httpsOptions.cert
                    }
                },
                open: false
            };
            callback(serverOptions);
        })
        .catch(error => {
            console.error("Error obtaining HTTPS options:", error);
            callback({});
        });
}

setupDevServer(devServerOptions => {
    config.devServer = Object.assign({}, config.devServer || {}, devServerOptions);
});
Also it is required to add npm dependency in jsMain target as such:
Copy code
jsMain.dependencies {
            implementation(npm("office-addin-dev-certs", "1.12.2"))
        }
👍 1
m
I don't think there is any difference here between Kotlin/JS and any other type of JS
m
Chrome does not recognize webpack's self signed certificate as secure.
m
You do not need to use https
m
I guess I asked the wrong question. I meant if it is possible to run kotlin/js over HTTPS. Sorry for confusion
Mainly a curiosity thing, I do not have actual use case 🙌
m
I don't think that is related to Kotlin/JS: once you build your production kotlin/JS (creating HTML, Javascripts, etc), then it can be served the same as any other HTML/JS e.g. Apache, Nginx, etc. Not really a Kotlin/JS question there.
m
Well, I used
kotlin/js
plugin to extend webpack config generated by said plugin and ran it using gradle. Not sure where else should I post it 🤔 The question may be misleading but the result is 100% applicable in kotlin/js
m
True; but thankfully, if you want to run your Kotlin/JS output in a secure context, you don't need any extra webpack config
🙌 1