无法从邮递员Node js错误500开机自检



我已经设置了工作正常的服务器,但是当我尝试通过在Postman中将详细信息写入应用程序/JSON来创建用户时,服务器返回:

POST /sign-up 500.

我试过放utf-8,是一样的。将其更改为表单编码,但随后显示:UnhandledPromiseRejectionWarning: Error: data and salt arguments required

const createUser = async (req, res, next) => {
const {
username, 
email, 
phonenumber,
password
}: {
username: string,
email: string,
phonenumber: string,
password: string
} = req.body;

const salt = bcrypt.genSaltSync(10);
const getRounds = bcrypt.getRounds(salt); 
const passHash = bcrypt.hashSync(password, getRounds);
const createAt = new Date(Date.now());
try {
const createNewUser = 'INSERT INTO Creations (username, email, phonenumber, password, salt, created_at) VALUES (?,?,?,?,?,?)';
con.query(createNewUser, [username, email, phonenumber, passHash, salt, createAt], (err, results) => {
if (err) {
console.error(err);
}
console.log(results);
});
res.status(201).send({ success: true, message: 'Created new user', body: {username, email, phonenumber, password} });
} catch (error) {
res.status(500).send({ success: false, message: 'Server error' });
}
await next; }

mainRouter.post('/sign-up', createUser);

app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json({ type: '*/*' }));

localhost:3002/sign-up

{
"username": "yoshi",
"email": "atw@gmailcom" ,
"phonenumber": "somthigna",
"password": "yesyes"
}

我不知道这里可能有什么问题,如果有人能帮忙,我正在尝试解决 2 天,那就太好了!

服务器给出错误 500,因为我没有正确设置数据库。对于遇到相同错误的人来说,这可能是它的原因。

相关内容

最新更新