1

Не могу понять в чем дело, суть данного запроса в том, чтобы передать некоторые данные, вызвать функцию и отправить назад сформированный Json файл, но этого не происходит, вместо этого сервер не возвращает ничего. В чем может быть проблема? Помогите, пожалуйста

Веб часть

 clickOnRow: function(elem, whichScreen){
          this.clicks++          
          
          if(this.clicks === 1) {
            var self = this
            this.timer = setTimeout(function() {            
            console.log("одинарный");                 
              self.clicks = 0
            }, this.delay);
          } else{
             clearTimeout(this.timer);
             console.log("двойной");
             
             elem['whichScreen']  = whichScreen;    
             console.log(this.helper);
            //  this.nameOfMethod(elem);
             this.clicks = 0; 
            fetch('/currentDir1',{
                    method: 'POST',
                    mode: 'cors',
                    headers: {
                        'Content-Type': 'application/json',                    
                    },
                    body: JSON.stringify(elem)                
                    })
                    .then(response => response.json())    
                    .then(json => this.helper = json)
                    .then(json =>  this.$emit("newvalue", json)) 
                    console.log("helper");
                    console.log(this.helper);

Серверная часть

router.post('/currentDir1',(req, req) =>{  
    console.log("POST");
    
    let body = "";   
    let pathToFile = "";
    req.on("data", function (data) {
        body += data;
    });
    
    req.on("end", function(currentData) {
        console.log(JSON.parse(body));
        currentData = JSON.parse(body);
        

        if(currentData.sizeOrType === "<папка>"){
            let dir = currentData.dir + currentData.fileName;
            // dir = "C:\\totalcmd";
            console.log(dir);                
            if(currentData.whichScreen){
                foo(dir, './data/firstScreen.json');
                pathToFile = './data/firstScreen.json';
                res.sendFile(path.resolve('./data/firstScreen.json'));
            }else{
                console.log('aaaa');
                Foo(dir, './data/secondScreen.json');
                pathToFile = './data/firstScreen.json';
                res.sendFile(path.resolve('./data/secondScreen.json'));
                
            }        
        }
    
        // res.json({ message: 'goodbye'})   
        res.json(path.resolve(pathToFile));     
    });
       
    res.sendFile(path.resolve(pathToFile));
})

1 ответ 1

0

router.post('/currentDir1',(req, req) =>{ тут два раза req

1
  • 4
    добро пожаловать на stack overflow на русском! пожалуйста, постарайтесь оставлять чуть более развёрнутые ответы. дополнить ответ можно, нажав править 22 июн 2021 в 17:06

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.