nwjs/nw.js

How to run axios in node js context with nw.js

wanematou opened this issue · 1 comments

Run axios in node js context with nw.js

I'm trying to read data like:

createIpBinding() {
            new Promise((resolve, reject)=>{
            const response= axios.put(`https://192.168.00.1:8383/rest/ip/hotspot/ip-binding`,
                    {
                            "mac-address": macAddress,
                            "type": byPassed,
                            
                    }, 
                    {
                             httpsAgent: new https.Agent({ rejectUnauthorized: false}),
                            auth: {
                            username: "admin",
                            password: "admin"
                            },
                            headers: {
                            'Content-Type': 'application/json',
                            }
                    },
            
            );
            console.log(response);
            if(response.data){
                    resolve(response)
            }else{
                    reject(response)
            }
            })
        },

but it sends me back self-signed certificate despite httpsAgent: new https.Agent({ rejectUnauthorized: false}).
So it's execute in node js context?

I usually do this:

index.html

<script>
delete window.require;
</script>

Somewhere else:

const node = {};
node.axios = nw.require('axios');

Make sure node-remote is set correctly for whatever you are trying to do:
https://nwjs.readthedocs.io/en/stable/References/Manifest%20Format/#node-remote