I am trying to post a comment to a nodejs server but i am getting 404 error. I have used cors module on server side to handles cors request. I am using typescript.
cors module: https://github.com/troygoode/node-cors
var app = express();
app.use(cors());
(<any>app).options('*', cors()); // include before other routes
app.use((<any>app).router);
Following is my endpoint code
app.post("/api/object/addcomment/:id", authenticatebearer(), (req, res) => {
var id = this.ParseInt(req.params.id);
var comment: string = req.body.CommentText;
if (this.IsNullOrUndefined(id) && this.IsNullOrUndefined(comment))
return this.SendInputError("input is empty.", res);
(new OM.ObjectManager()).AddComment(req.user.userId, id, comment, (err, commentId) => {
if (err) return this.SendInternalError(err.message, res);
return res.json(commentId);
});
});
I am calling above endpoint from angularjs app,
myApp.config(function ($httpProvider) {
$httpProvider.defaults.useXDomain = true;
delete $httpProvider.defaults.headers.common['X-Requested-With'];
});
function addComment(id, comment, callback) {
var URL = Client.Config.RestUrl + "api/object/addcomment/" + id.toString() + '?access_token=' + this.RootScope.LogInUser.accessToken;
this.$http.post(URL, JSON.stringify({ CommentText: comment }))
.success((commentId, status) => {
callback(null, commentId);
})
.error((data, status) => {
callback(new Error("An unexpected error occured while adding comment."), null);
});
}
This code is working properly in the desktop environment. Please see the network log from chrome,
In phonegap, the function call executes successfully and the comment is added to the system but the $http.post is giving 404 error (gets response in error callback). Please see the network log from adb debugging tool (this works with android 4.4.2),
I am struggling for this from last two day. Unable to find a solution. Please help me. Thanks in advance. Sorry for my english.