我收到内部服务器500错误,并且在以下代码中未打印Last Console.log()...
以下是我的项目设置简介...
是使用express-generator生成的项目。
在我的App.js(我已经包含一个路由处理程序)中,作为Express-generator的一部分生成的原始App.js文件如下所示:
var chatMessageRouter = require('./ routes / rcChatRouter'); app.use('/ restcomm',chatMessageRouter);
我的rcChatRouter.js文件如下...
var rcExpress = require('express');
var rcRouter = rcExpress.Router();
const CustomerStore = require('../customerStore.js');
const Customer = require('../Customer.js');
const customerStore = new CustomerStore();
var custParams ={};
var customerObj = {};
rcRouter.post('/askbot', (req,res) => {
console.log('Inside /restcomm/askbot post handler....posting the
reqeust to DF-BOT');
custParams = {
'username': req.body.rcsipLogin,
'password': req.body.rcsipPassword,
'customerID' : req.body.custID,
'message':req.body.message,
'mode':CustomerStore.MODE_AGENT
};
console.log('custParams is...'+ JSON.stringify(custParams));
customerObj = customerStore.getCustomer(req.body.custID);
console.log('received customer is...' + JSON.stringify(customerObj));
if(!customerObj) {
customerObj = new Customer(custParams);
console.log('Storing new customer with id: '+ req.body.custID);
console.log('newly created customer is...' +
JSON.stringify(customerObj));
customerStore.setCustomer(req.body.custID, customerObj);
customerObj = customerStore.getCustomer(req.body.custID);
console.log('customer store after map update is..' +
JSON.stringify(customerObj));
}
})
module.exports = rcRouter;
我的CustomerStore.js文件如下...
CustomerStore类{
constructor () {
this.sessionMap = new Map();
}
static get MODE_AGENT () {
return 'AGENT';
}
static get MODE_OPERATOR () {
return 'OPERATOR';
}
getCustomer(customerId) {
console.log('inside getCustomer of customer store');
return this.sessionMap.get(customerId);
}
setCustomer(custId, custObj) {
this.sessionMap.set(customerId, custObj);
}
}
module.exports = CustomerStore;
我的CustomerStore.js文件如下...
类客户{
构造函数(custParams){
// 顾客信息
console.log('在新的Customer()内部管理员和客户详细信息
是.....'+ JSON.stringify(custParams));
this.custDeails = custParams;
}
} //课程结束
module.exports =客户;
但是当我发布请求时,请求被正确地路由到了“ rcChatRouter.js”,一切都很好,但是它抛出内部服务器错误500,而没有输出最后的“ Console.log()”( ie console.log(“地图更新后的客户商店是.. + JSON.stringify(customerObj));甚至控件也进入了“ if(!customerObj){}块”。
我尝试了多种选择,但是我不确定导出方式和要求使用“ CustomerStore”和“ Customer”类的方式是否有误。
PL。事先澄清并感谢