Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/426.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript GET请求nodejs reactjs上出现410(已消失)错误_Javascript_Node.js_Reactjs_Mongodb_Express - Fatal编程技术网

Javascript GET请求nodejs reactjs上出现410(已消失)错误

Javascript GET请求nodejs reactjs上出现410(已消失)错误,javascript,node.js,reactjs,mongodb,express,Javascript,Node.js,Reactjs,Mongodb,Express,现在,我在控制台中收到一条奇怪的消息,说当我在react组件中提交注册表单时 GEThttp://localhost:3000/api/v1/users/checkValidUser/sam123@gmail.com 410(消失) 在这里,我检查输入电子邮件的用户是否存在于数据库中 handleSubmit=async(事件)=>{ event.preventDefault() const{username,email,password}=this.state 日志(“内部检查有效电子邮件

现在,我在控制台中收到一条奇怪的消息,说当我在react组件中提交注册表单时

GEThttp://localhost:3000/api/v1/users/checkValidUser/sam123@gmail.com 410(消失)

在这里,我检查输入电子邮件的用户是否存在于数据库中


handleSubmit=async(事件)=>{
event.preventDefault()
const{username,email,password}=this.state
日志(“内部检查有效电子邮件”,电子邮件)
const res=等待axios.get(`http://localhost:3000/api/v1/users/checkValidUser/${email}`)
console.log(res.data)
}
router.get(“/checkValidUser/:email”,userscocontroller.checkValidUser)

checkValidUser:async(请求、恢复、下一步)=>{
日志(“内部检查有效用户控制器”)
const{email}=req.params
控制台日志(电子邮件)
试一试{
const user=await user.findOne({email})
如果(用户){
返回res.status(200).json({message:“用户已存在”})
}否则{
返回res.status(400.json)({message:“未找到此电子邮件的用户。您现在可以注册”})
}
}捕获(错误){
返回下一个(错误)
}
}
在《邮递员》中,路线运行良好。目前,我已经删除了数据库,没有用户。因此,它应该会向我返回消息
“此电子邮件未找到任何用户。您现在可以注册”
,但获得410。请帮忙

app.js

const createError = require('http-errors');
const express = require('express');
const bodyParser = require('body-parser')
const path = require('path');
const cookieParser = require('cookie-parser');
const logger = require('morgan');
const mongoose = require("mongoose")


const indexRouter = require('./routes/index');
const userRouter = require('./routes/users');

const app = express();


// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');


app.use(logger('dev'));
app.use(express.json());
app.use(bodyParser.json())
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

if (process.env.NODE_ENV === "development") {
  const webpack = require("webpack");
  const webpackConfig = require("./webpack.config");
  const compiler = webpack(webpackConfig);

  app.use(
    require("webpack-dev-middleware")(compiler, {
      noInfo: true,
      publicPath: webpackConfig.output.publicPath
    })
  );

  app.use(require("webpack-hot-middleware")(compiler));
}

mongoose.connect("mongodb://localhost:27017/myApp", {useNewUrlParser: true, useUnifiedTopology: true, useFindAndModify: false}, function(err) {
  if (err) {
    console.log("Not connected to the database")
  } else {
    console.log("Connected to the database")
  } 
})


app.use("/api/v1/users", userRouter)
app.use("/*", indexRouter)

// catch 404 and forward to error handler
app.use(function(req, res, next) {
  next(createError(404));
});

// error handler
app.use(function(err, req, res, next) {
  // set locals, only providing error in development
  res.locals.message = err.message;
  res.locals.error = req.app.get('env') === 'development' ? err : {};

  // render the error page
  res.status(err.status || 500);
  res.render('error');
});


module.exports = app;
bin/www

#/usr/bin/env节点
/**
*模块依赖关系。
*/
var-app=require('../app');
var debug=require('debug')('myApp:server');
var http=require('http');
/**
*从环境中获取端口并存储在Express中。
*/
var port=normalizePort(process.env.port | |“3000”);
应用程序集(“端口”,端口);
/**
*创建HTTP服务器。
*/
var server=http.createServer(app);
/**
*在提供的端口、所有网络接口上侦听。
*/
监听(端口);
server.on('error',onError);
server.on('listing',onListening);
/**
*将端口规范化为数字、字符串或false。
*/
函数normalizePort(val){
var port=parseInt(val,10);
如果(伊斯南(港口)){
//命名管道
返回val;
}
如果(端口>=0){
//端口号
返回端口;
}
返回false;
}
/**
*HTTP服务器“错误”事件的事件侦听器。
*/
函数onError(错误){
if(error.syscall!=='listen'){
投掷误差;
}
var bind=typeof端口==='string'
?管道+端口
:“港口”+港口;
//使用友好消息处理特定的侦听错误
开关(错误代码){
案例“EACCES”:
错误(绑定+'需要提升的权限');
过程。退出(1);
打破
案例“EADDRINUSE”:
错误(bind+'已在使用');
过程。退出(1);
打破
违约:
投掷误差;
}
}
/**
*HTTP服务器“侦听”事件的事件侦听器。
*/
函数onListening(){
var addr=server.address();
var bind=typeof addr=='string'
?管道+地址
:“端口”+地址端口;
调试('监听'+绑定);
}

这是否回答了您的问题?不,我没有得到我上一个问题的答案。所以,我又问了一遍。你不应该问重复的问题。请删除其中一个。删除了以前的帖子。只是不要使用www文件夹中的文件,使用app listen中的任何端口号。这是否回答了您的问题?不,我没有得到我上一个问题的答案。所以,我又问了一遍。你不应该问重复的问题。请删除其中一个。删除了以前的帖子。只是不要使用www文件夹中的文件,而是使用app listen中的任何端口号。