javascript – problemas con fecth async y await en servirdor


window.addEventListener('load',function(){
    selectWords();
}, false);

let boxCon = document.querySelector('#boxCon');
let boxPro = document.querySelector('#boxPro');
let boxSer = document.querySelector('#boxSer');
let boxSus = document.querySelector('#boxSus');
let boxVer = document.querySelector('#boxVer');
let boxAdj = document.querySelector('#boxAdj');
let boxPoema = document.querySelector('#boxPoema');

function selectWords(){
    let boton1 = document.querySelectorAll('.botonet4');
    boton1.forEach(function(boton1){
        boton1.addEventListener('click',function(e){
            const getWordsAsync = async () => {
                try {

                    const respPro = await fetch(base_url+'poema/pronombres');
                    const pro = await respPro.json();
                    for(let i = 0; i < pro.length; i++) {
                        let pronombreB = document.createElement('button');
                        let txtPro = document.createTextNode(pro(i).pronombre);
                        pronombreB.classList.add("pro");
                        pronombreB.appendChild(txtPro);
                        boxPro.appendChild(pronombreB);
                    }

                    let pronomc = document.querySelectorAll('.pro');
                    pronomc.forEach(function(pronomc){
                        pronomc.addEventListener('click',function(){
                            //boxPro.removeChild(pronombre);
                            let wordPoem = document.createElement('button');
                            wordPoem.classList.add('wordPoem');
                            let content = document.querySelector('#contenido');
                            let pronom = pronomc.innerHTML;
                            console.log(pronom);
                            content.value += pronom + ' ';
                            wordPoem.innerText = pronom;
                            boxPoema.appendChild(wordPoem);
                            wordPoem.addEventListener('click', function(){
                                boxPoema.removeChild(wordPoem);
                                content.value = content.value.replace(pronom + ' ','');
                            });
                        });
                    });

                    const respSer = await fetch(base_url+'poema/seres');
                    const ser = await respSer.json();
                    for(let i = 0; i < ser.length; i++) {
                        let serB = document.createElement('button');
                        serB.classList.add('ser');
                        let txtSer = document.createTextNode(ser(i).ser);
                        serB.appendChild(txtSer);
                        boxSer.appendChild(serB);    
                    }

                    let serB2 = document.querySelectorAll('.ser');
                    serB2.forEach(function(serB2){
                        serB2.addEventListener('click',function(){
                            boxSer.removeChild(serB2);
                            let wordPoem = document.createElement('button');
                            wordPoem.classList.add('wordPoem');
                            let content = document.querySelector('#contenido');
                            let ser2 = serB2.innerHTML;
                            content.value += ser2 + ' ';
                            wordPoem.innerText = ser2;
                            boxPoema.appendChild(wordPoem);
                            wordPoem.addEventListener('click', function(){
                                boxPoema.removeChild(wordPoem);
                                content.value = content.value.replace(ser2 + ' ','');
                            });
                        });
                    });
                    
                    const respAdj = await fetch(base_url+'poema/adjetivos');
                    const adj = await respAdj.json();
                    for(let i = 0; i < adj.length; i++) {
                        let adjetivo = document.createElement('button');
                        adjetivo.classList.add('adj');
                        let txtAdj = document.createTextNode(adj(i).adjetivo);
                        adjetivo.appendChild(txtAdj);
                        boxAdj.appendChild(adjetivo);
                    }

                    let adjB2 = document.querySelectorAll('.adj');
                    adjB2.forEach(function(adjB2){
                        adjB2.addEventListener('click',function(){
                            boxAdj.removeChild(adjB2);
                            let wordPoem = document.createElement('button');
                            wordPoem.classList.add('wordPoem');
                            let content = document.querySelector('#contenido');
                            let adj2 = adjB2.innerHTML;
                            content.value += adj2 + ' ';
                            wordPoem.innerText = adj2;
                            boxPoema.appendChild(wordPoem);
                            wordPoem.addEventListener('click', function(){
                                boxPoema.removeChild(wordPoem);
                                content.value = content.value.replace(adj2 + ' ','');
                            });
                        });
                    });

                    const respVer = await fetch(base_url+'poema/verbos');
                    const ver = await respVer.json();
                    for(let i = 0; i < ver.length; i++) {
                        let verB = document.createElement('button');
                        verB.classList.add('ver');
                        let txtVer = document.createTextNode(ver(i).verbo);
                        verB.appendChild(txtVer);
                        boxVer.appendChild(verB);
                    }

                    let verB2 = document.querySelectorAll('.ver');
                    verB2.forEach(function(verB2){
                        verB2.addEventListener('click',function(){
                            boxVer.removeChild(verB2);
                            let wordPoem = document.createElement('button');
                            wordPoem.classList.add('wordPoem');
                            let content = document.querySelector('#contenido');
                            let ver2 = verB2.innerHTML;
                            content.value += ver2 + ' ';
                            wordPoem.innerText = ver2;
                            boxPoema.appendChild(wordPoem);
                            wordPoem.addEventListener('click', function(){
                                boxPoema.removeChild(wordPoem);
                                content.value = content.value.replace(ver2 + ' ','');
                            });
                        });
                    });

                    const respCon = await fetch(base_url+'poema/conectores');
                    const con = await respCon.json();
                    for(let i = 0; i < con.length; i++){
                        let conn = document.createElement('button');
                        conn.classList.add('con');
                        let txtCon = document.createTextNode(con(i).conector);
                        conn.appendChild(txtCon);
                        boxCon.appendChild(conn);
                    }
                    
                    let conB2 = document.querySelectorAll('.con');
                    conB2.forEach(function(conB2){
                        conB2.addEventListener('click',function(){
                            boxCon.removeChild(conB2);
                            let wordPoem = document.createElement('button');
                            wordPoem.classList.add('wordPoem');
                            let content = document.querySelector('#contenido');
                            let conec = conB2.innerHTML;
                            content.value += conec + ' ';
                            wordPoem.innerText = conec;
                            boxPoema.appendChild(wordPoem);
                            wordPoem.addEventListener('click', function(){
                                boxPoema.removeChild(wordPoem);
                                content.value = content.value.replace(conec + ' ','');
                            });
                        });
                    });

                    const respSus = await fetch(base_url+'poema/sustantivos')
                    const sus = await respSus.json()
                    for(let i = 0; i < sus.length; i++) {
                        let susB = document.createElement('button');
                        susB.classList.add('sus');
                        let txtSus = document.createTextNode(sus(i).sustantivo);
                        susB.appendChild(txtSus);
                        boxSus.appendChild(susB);
                    }

                    let susB2 = document.querySelectorAll('.sus');
                    susB2.forEach(function(susB2){
                        susB2.addEventListener('click',function(){
                            boxSus.removeChild(susB2);
                            let wordPoem = document.createElement('button');
                            wordPoem.classList.add('wordPoem');
                            let content = document.querySelector('#contenido');
                            let sus2 = susB2.innerHTML;
                            content.value += sus2 + ' ';
                            wordPoem.innerText = sus2;
                            boxPoema.appendChild(wordPoem);
                            wordPoem.addEventListener('click', function(){
                                boxPoema.removeChild(wordPoem);
                                content.value = content.value.replace(sus2 + ' ','');
                            });
                        });
                    });

                }catch(error){
                    console.log(error);
                }
            }
            getWordsAsync();
            boton1.style.display = "none";
        });     
        
    });
}