I used to have an Azure Mobile Service with a JavaScript backend. Now I switched to the new Azure Mobile App with its node.js backend. Since things are handled differently with node.js, I want to ask you how to do some simple things that used to work with the older backend.
The first thing is, how can I modify a "read" or "insert" request on the server side to, for instance, execute a custom query. I used to do that like this:
function read(query, user, request) {
var visitorID = request.parameters.visitor;
var liked = request.parameters.liked;
var link = request.parameters.link;
if (visitorID && !liked && !link) {
if (visitorID.indexOf(" ") == -1) {
var sqlUnique = "SELECT TOP 1 * FROM ........;";
mssql.query(sqlUnique, {
success: function(results) {
if(results.length > 0) {
request.respond(statusCodes.OK, results);
}
else {
request.respond(statusCodes.BAD_REQUEST, {error: 'An error message.'});
}
},
error: function(err) {
request.respond(statusCodes.BAD_REQUEST, {error: 'There was a problem with the request.'});
}
});
} else {
request.respond(statusCodes.BAD_REQUEST, {error: 'Invalid username.'});
}
}
else {
// no server-side action needed
request.execute();
}
}
As you can see, whenever a client reads from the server, some other things are getting executed. My question is now, how to do that same thing with Azure Mobile App's node.js backend. Especially when a client passes some parameters within the request. How can I read those parameters in node.js? And how can I execute a custom query before executing the query in the request?
If someone can help me port the above JavaScript code to node.js, I would be very happy!