简体   繁体   English

POST http://localhost:3000/api/login 404(未找到)

[英]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.

相关问题 发布 http://localhost:3000/api/auth/register 404(未找到) - POST http://localhost:3000/api/auth/register 404 (Not Found) POST http://localhost:3000/api/customers 404(未找到)reactjs nodejs - POST http://localhost:3000/api/customers 404 (Not Found) reactjs nodejs POST http:// localhost:3000/404(未找到) - POST http://localhost:3000/ 404 (Not Found) 发布 localhost:3000/api/users 404 未找到 - Post localhost:3000/api/users 404 not found 错误“POST http://localhost:3000/api/auth/createuser(与 /api/auth/login 路径相同)404(未找到)”和“未在 Promise 中捕获:语法错误” - Error "POST http://localhost:3000/api/auth/createuser (same with /api/auth/login path) 404 (Not Found)" & "Uncaught in Promise: Syntax Error" React.js / Firebase 应用程序中的 Axios 错误(404):POST http://localhost:3000/login 404(未找到) - Axios error (404) in React.js / Firebase app: POST http://localhost:3000/login 404 (Not Found) 登录页面上的控制台 POST http://localhost:3000/login/signin 404(未找到)错误 - Error on console POST http://localhost:3000/login/signin 404 (Not Found) on Login page 我不断收到 http POST http://localhost:3000/api/authenticate 404(未找到) - I keep getting http POST http://localhost:3000/api/authenticate 404 (Not Found) POST http://localhost:3000/undefined/post 404(未找到) - POST http://localhost:3000/undefined/post 404 (Not Found) 加载资源失败:服务器响应状态为 404(未找到)POST http://localhost:3000/login 404(未找到)? firebase 反应 - Failed to load resource: the server responded with a status of 404 (Not Found) POST http://localhost:3000/login 404 (Not Found) ? firebase react
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM