此代码“ Status 500出现错误,并在与Docker检查时出现错误消息”是什么错误?

时间:2019-05-24 22:38:26

标签: node.js express mongoose

这是我的新快递应用程序的简单登录。但是当我在邮递员上测试它们时,我只会收到状态500消息。

我尝试了堆栈溢出的所有问题

Route.js
{
var Express         = require("express");
var Routes          = Express.Router();
var UserRoute       = require('./src/User/User.Route');
var CommentRoute    = require('./src/Comment/Comment.Route');

Routes.use('/user/', UserRoute);
Routes.use('/comment/', CommentRoute);

module.exports = Routes;
}

app.js {

const Express       = require("express");
const BodyParser    = require("body-parser");
const Routes        = require("./Routes");
const Cors          = require("cors");

const app = Express();
app.use(Cors());

app.use(BodyParser.urlencoded({ extended: false }));
app.use(BodyParser.json());
app.use('/', Routes);

app.listen(8083, 'localhost', (err) => {
    if(err) {
        console.log(err);
        process.exit(-1);
    }
    console.log("Server listen port 8083");
});

}

  

这是路线。我曾经在该项目中进行路线制作的js页面

{
var mongoose        = require('mongoose');
const Schema        = mongoose.Schema;

const UserSchema = new Schema({
    userName: {
        type: String,
        require: true
    },
    password: {
        type: String,
        require: true
    }
});

mongoose.model('User', UserSchema);
mongoose.model('Comment', CommentSchema);

mongoose.connect('mongodb://localhost:27017/comments', (err) => {
    if (err) {
        console.log(err);
        process.exit(-1);
    }
    console.log('Connected to the DB');
});

module.exports = mongoose;
}
  

//用户。路由

var express     = require('express');
var router      = express.Router();
var Controller  = require('./User.Controller');

router.post('/', (req, res) => {
    Controller.insert(req.body).then(data => {
        res.status(data.status).send({message: data.message});
    }).catch(err => {
        res.status(err.status).send({message: err.message});
    })
});


router.put('/:id', (req, res) => {
    Controller.update(req.params.id, req.body).then(data => {
        res.status(data.status).send({message: data.message});
    }).catch(err => {
        res.status(err.status).send({message: err.message});
    })
});
  

//控制器

var mongoose        = require('../DBSchema/SchemaMapper');
var UserSchema      = mongoose.model('User');

var UserController = function(){
    this.insert = (data) => {
        return new Promise((resolve, reject) => {
            var user = new UserSchema({
                userName: data.userName,
                password: data.password
            });
            user.save().then(() => {
                resolve({status: 200, message: "Added new user"});
            }).catch(err => {
                reject({status: 500, message: "Error:- "+err});
            })
        })

    }

this.searchAll = () => {
        return new Promise((resolve, reject) => {
            UserSchema.find().exec().then((data) => {
                resolve({status: 200, data: data});
            }).catch(err => {
                reject({status: 500, message: "Error:- " + err});
            })
        })
    }
  

我想知道如何在邮递员和语法上正确运行此应用程序   错误。

0 个答案:

没有答案