我正在创建一个注册页面,其中接受一些细节并将其存储在mongoDB中。但是,必须存在一些我无法理解的错误。我能够从UI正确检索数据。然后我将这些数据通过server.js路由到app.controller.js,再从那里路由到app.service.js。
我收到错误-
POST http://localhost:3003/register/registerObjectData/ 404 (Not Found)
这是我的代码。请帮助我找出我的错误-
app.component.ts
register(registerData){
console.log("inside Register()");
this.registerObjectData = {
'userName': registerData.userName,
'email': registerData.email,
'firstPassword': registerData.firstPassword,
'repeatPassword': registerData.repeatPassword,
'phone': registerData.phone,
'company':registerData.company
}
this.http.post("http://localhost:3003/register/registerObjectData/"
, JSON.stringify(this.registerObjectData))
.map(Response => Response)
.catch((err) => {
console.log("err =", err)
return Observable.throw(err);
})
.subscribe((res: Response) => {
console.log("XXXXXXXXX Register Response ", res);
})
}
server.js
var express = require('express');
var cors = require('cors');
var bodyParser = require('body-parser');
//more definitions and var
app.listen(app.get('port'), function(){
console.log('Express server on port ' + app.get('port'));
});
app.use('/register', require('./api-mine-server/controller/register-
controller.js'));
app.controller.js
var express = require('express');
var router = express.Router();
var userService = require('../service/registerService');
var app = express();
router.post('/registerObjectData/:registerObjectData', registerUser);
module.exports = router;
function registerUser (req, res){
console.log("registerUser , BODY IS, JSON.parse,req ", JSON.parse(req.params.registerObjectData));
userService.registerUser(req,res)
.then(function (data) {
console.log("data after registration = ",data)
if(data == 'Registration Successful.'){
var set = {
data : data
}
res.send(set);
}
else{
res.send(data);
}
})
.catch(function (err) {
res.status(400).send('Something went wrong. Status 400');
});
}