简体   繁体   中英

there is 404 error with axios(react) and express

this is my react code

 <button type='submit' onClick={()=>{axios.get('https://eccwithnodejs.df.r.appspot.com:443/user').then((res)=>{console.log(res.data)}).catch(error => {
        console.log(error.response)
    });}} >버튼</button>

and these are my node js code with express

this is create server code

    var server=http.createServer(app).listen(8080,function(){
        console.log('succesful');
    })
    
    https.createServer(options,app).listen(443,function(){
        console.log('succesful https');
    })

this is get method

app.get('https://eccwithnodejs.df.r.appspot.com:443/user',function(req,res){
var tempUser={"name":"asd",
"birth":970204,
"email":"으헤헤헤이거슨이메일",
"uid":"유니크다음은 전설"
}

res.send(tempUser);
console.log(tempUser);
})

and I got errorcode 404 like this

{data: '<!DOCTYPE html>\n<html lang="en">\n<head>\n<meta char…ody>\n<pre>Cannot GET /user</pre>\n</body>\n</html>\n', status: 404, statusText: '', headers: {…}, config: {…}, …}

What is the problem? please help... :(

In your get method, you also need to mention the endpoint not full domain name. So, remove your domain name from the get method.

app.get(/user',function(req,res){
var tempUser={"name":"asd",
"birth":970204,
"email":"으헤헤헤이거슨이메일",
"uid":"유니크다음은 전설"
}

now change your react code.

<button type='submit' onClick={()=>{axios.get('https://<<your_domain>>:8080/user').then((res)=>{console.log(res.data)}).catch(error => {
        console.log(error.response)
    });}} >버튼</button>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM