Добрый день, пытаюсь сделать простую аутентификацию и регистрацию на базе Express+node.js+react+mysql, выдает ошибку "http://localhost:3001/login 404 (Not Found)" при нажатии на кнопку логин, причем регистрация работает, в базу пишет, уже все перепробовал, не понимаю почему не видит ссылки с логином
App.js
//import logo from './logo.svg';
import React, {useState} from "react";
import Axios from 'axios'
import "./App.css";
import 'bootstrap/dist/css/bootstrap.min.css';
function App() {
const [usernameReg,setUsernameReg]=useState("");
const [passwordReg,setPasswordReg]=useState("");
const [username,setUsername]=useState("");
const [password,setPassword]=useState("");
const [loginStatus,setLoginStatus]=useState("");
const login=()=>{
Axios.post('http://localhost:3001/login',{
username:username,
password:password,
}).then((response)=>{
if (response.data.message){
setLoginStatus(response.data.message)
}else{
// setLoginStatus(response.data[0].usernameLogin)
setLoginStatus(response.data[0].message)
}
});
};
const register=()=>{
Axios.post('http://localhost:3001/register',{
username:usernameReg,
password:passwordReg,
}).then((response)=>{console.log(response);
});
};
return (
<div className="App">
<div className="registration">
<h1>Registration</h1>
<label>Username</label>
<input type="text" onChange={(e)=>{setUsernameReg(e.target.value);}}/>
<label>Password</label>
<input type="text" onChange={(e)=>{setPasswordReg(e.target.value);}}/>
<button onClick={register} className="btn btn-primary"> Register </button>
</div>
<div className="login">
<h1>Login</h1>
<input type="text" placeholder="Username..." onChange={(e)=>{setUsername(e.target.value);}}/>
<input type="password" placeholder="Password..." onChange={(e)=>{setPassword(e.target.value);}}/>
<button onClick={login}>Login</button>
</div>
<h1>{loginStatus}</h1>
</div>
);
}
export default App;
const express=require("express")
const mysql=require("mysql2")
const cors=require("cors");
const port = process.env.PORT || 3001
index.js
const app=express();
app.use(express.json());
//app.use(cors());
app.use(
cors({
origin: ["http://localhost:3000"],
methods: ["GET", "POST"],
credentials: true,
})
);
const db=mysql.createConnection({
user:"root",
host:"localhost",
password:"root",
database:"main_db",
});
app.post("/register",(req,res)=>{
const username=req.body.username;
const password=req.body.password;
db.query("INSERT INTO test (username,password) VALUES (?,?)",
[username,password],
(err,result)=>{
console.log(err);})
});
app.post("/login,",(req,res)=>{
const username=req.body.username;
const password=req.body.password;
db.execute("SELECT * FROM test WHERE username = ? AND password = ?",
[username,password],
(err,result)=>{
if (err) {
res.send({err: err});
}
if (result.length>0) {
res.send(result);
} else {
res.send({message: "Wrong username/password combination!"});
}
}
);
});
app.listen(port, function() {
console.log('Server is running on port: ' + port)
})