[英]POST http://localhost:3000/api/login 404 (Not Found)
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我一直在配置与 nodejs 在同一文件夹中链接的数据库,以便能够作为程序员进一步发展,我尝试向数据库发出 ajax 请求,但它给了我一个错误,好像数据库已关闭或 url 错误
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我之前已经提出了 ajax 请求,但是我在同一个 node.js 内执行此操作的时间,如果有人知道如何解决,请帮助我
var app = express();
const controllers = require('../controllers/controllers')
const cors = require('cors')
var bodyParser = require('body-parser');
var port = process.env.PORT || 3013;
app.use(bodyParser.json());
app.use(cors(corsOption));
var server = require('http').Server(app);
server.listen(port, function () {
console.log('Updated : Server listening at ports', port);
});
app.post('/api/register', controllers.registerUser)
app.post('/api/login', controllers.loginUsers)
aapppi.get('/api/test', controllers.test)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.