我在AWS上部署了MEAN Stack网站。网站在我的本地运行良好。 但是当我尝试访问DB(MongoDB)时,它会在部署后显示POST / xxx / register 500(内部服务器错误)。
我已经像下面的流程一样部署了它。
而且似乎是DB访问问题。 例如,当我厌倦了在实时服务器上注册用户Putty如下所示
POST / api / v1 / register 500 35.645 ms - 1675
app.js
var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var session = require('express-session');
var https = require('https');
var mongoose = require('mongoose');
var passport = require('passport');
mongoose.connect('mongodb://localhost/news');
require('./models/Users');
require('./config/passport');
var index = require('./routes/index');
var authenticate_api = require('./routes/authenticate_api');
app.use('/', index);
app.use('/api/v1/', authenticate_api);
和route / authenticate_api.js文件
var mongoose = require('mongoose');
var passport = require('passport');
var User = mongoose.model('User');
require('../config/passport');
var express = require('express');
var router = express.Router();
var jwt = require('express-jwt');
var auth = jwt({secret: 'SECRET', userProperty: 'payload'});
router.post('/register', function(req, res, next) {
if (!req.body.username || !req.body.password) {
return res.status(400).json({message: 'Please fill out all fields'});
}
var user = new User();
user.username = req.body.username;
user.setPassword(req.body.password);
user.save(function(err, user) {
if(err) {
return next(err);
}
return res.json({token: user.generateJWT()});
});
})
module.exports = router;
那有什么关系? 欢呼声。
答案 0 :(得分:0)
我自己刚刚解决了。 这是一个mongoDB权限问题 我可以发现mongodb状态总是停止/等待。 所以我解决了它,如下所示。
@charset "utf-8";
/* CSS Document */
body {
font-family: 'Droid Sans', sans-serif;
margin-top: 0px;
margin-left: 0px;
margin-right: 0px;
margin-bottom: 0px;
min-height: 100%;
}
.div_top1 {
height: 30px;
margin: 0 auto;
width: 100%;
border-bottom: 1px solid #FFF;
background-color: #2d2d2d;
}
.div_top2 {
height: 150px;
width: 100%;
background-color: #072135;
}
.main_container {
width: 100%;
margin: 0 auto;
background-color: #FFF;
overflow: auto;
min-height: 100%;
display: inline-block;
}
.container_right {
height: 100%;
padding-left: 20px;
margin: 0 auto;
}
.container_left {
float: left;
text-align: left;
border-right: 2px solid #5a5c5d;
border-bottom: 1px solid #5a5c5d;
height: 100%;
overflow: hidden;
}
.bk {
border-top: 4px solid #da6161;
display: table;
height: 200px;
margin: 0 auto;
margin-top: 30px;
padding: 8px;
}
.icon {
float: left;
display: block;
}
.icon-bar {
width: 70px;
/* Set a specific width */
background-color: #FFF;
/* Dark-grey background */
height: 100%;
}
.icon-bar a {
display: block;
/* Make the links appear below each other instead of side-by-side */
text-align: center;
/* Center-align text */
padding: 16px;
/* Add some padding */
transition: all 0.3s ease;
/* Add transition for hover effects */
color: black;
/* White text color */
font-size: 27px;
/* Increased font-size */
height: 100%;
}
.icon-bar a:hover {
background-color: #5a5c5d;
/* Add a hover color */
}
.active {
background-color: #818384;
/* Add an active/current color */
}
<style>
/* Tooltip container */
.tooltip {
position: relative;
display: inline-block;
border-bottom: 1px dotted black;
/* If you want dots under the hoverable text */
}
/* Tooltip text */
.tooltip .tooltiptext {
visibility: hidden;
width: auto;
background-color: #da6161;
color: #fff;
text-align: center;
padding: 5px;
border-radius: 6px;
font-size: 20px;
/* Position the tooltip text - see examples below! */
position: absolute;
z-index: 1;
margin-left: 36px;
}
/* Show the tooltip text when you mouse over the tooltip container */
.tooltip:hover .tooltiptext {
visibility: visible;
}
.foot {
background-color: #2d2d2d;
position: absolute;
color: #FFF;
text-align: center;
left: 0;
bottom: 0;
height: 35px;
width: 100%;
border-top: 3px solid #9c9d9e;
padding-top: 3px;
}
现在效果很好。谢谢你的考虑。