'Ldap JS Node giving timeout error

I am trying to use the ldap js library in my node project "ldapjs": "^1.0.2". I have succesfully made the connection with the ldap server and getting the results back. But due to some reason, I am getting timeout error when I am trying to call my service from UI for the ldap. It works fine if I try to use my back end service directly in chrome (as it is a get service) but when I try from my ui code, the ldap service goes down. I get time out error in the console.

My back end is in Node and fron end code is in Vue. I am using axios to call my backend service.

ldap Code :

function getUserLdapDetails(id) {
    return new Promise(async function (resolve, reject) {
        var client;
        try {
            var response = {};
            setTimeout(function () {
                resolve('Not able to get Ldap details');
            }, 5000);
            var tlsOption = {
                'rejectUnauthorized': true
            }
            client = ldap.createClient({
                url: server,
                tlsOptions: tlsOption
            });
            client.bind(userPrincipalName, password, (err, res) => {
                console.log("In Ldap Bind and connection is establised :" + client.connected);
                if (err) {
                    console.log(err);
                    return reject(err);
                }
            });
            var opts = {
                filter: "id=" + id,
                scope: "sub",
                attributes: [
                    "mail",
                    "sn",
                    "telephoneNumber",
                    "givenName"                   
                ]
            };
            client.search(searchOption, opts, function (err, res) {
                if (err) {
                    console.log(err);
                    resolve(response);
                }
                res.on("searchEntry", function (entry, end) {
                    response.mail = entry.object.mail;
                    response.lastName = entry.object.sn;
                    response.firstNme = entry.object.givenName;
                    response.phone = entry.object.telephoneNumber;
                    resolve(response);
                });
            });
        } catch (err) {
            console.log(err);
            return reject(err);
        } finally {
            client.unbind(function (err) {
                if (err) {
                    console.log(err);
                    return reject(err);
                }
            });
        }
    }).catch((err) => {
        console.log(err);
        return err;
    });
}

Error: enter image description here



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source