I have been configuring my database that is linked with nodejs in the same folder, to be able to advance a little more as a programmer, and I try to make an ajax request to the database, but it gives me an error as if the database was off or the url was wrong
POST http://localhost:3000/api/login 404 (Not Found)
This is the petition code
userLogin = (username, password) =>{
const url = 'http://192.168.1.7:3000/api/login'
console.log('hola')
fetch('/api/login', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({username: username, password: password})
})
.then(r => r.json())
.then(data =>{
if(data.status === 200){
console.log('hola')
this.setState({
status: data.status,
message: data.message,
username: username
})
this.userSearch()
}
})
}
Routes:
const express = require('express');
const api = express.Router();
const controllers = require('../controllers/controllers')
const cors = require('cors')
api.post('/register', controllers.registerUser)
api.post('/login', controllers.loginUsers)
api.get('/test', controllers.test)
module.exports = api;
I have already made ajax requests before but the time I do it within the same node.js, if someone knows how to solve it please help me
question from:
https://stackoverflow.com/questions/65906536/post-http-localhost3000-api-login-404-not-found 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…