1
votes

Using Azure and I use web apps and mobile services. It appears that the Mobile Service is Missing some components which restrict my ability to do traditional/best practice routing. When I clone and examine the project, it appears to lacks index files that exist in an Azure Web App or any home brewed server. Please offer any advice or knowledge that you have about best practice and any modifications to what I have set up for our mobile service.

The below code was how I designed our Mobile Service APIs since they appears to lack an index. Perhaps I should make a dedicated API to tie everything together? Any advice or experience would help us make the right decision. Thanks.

var express = require('express');
    var app = module.exports = express();
    var bodyParser = require('body-parser');


//configure bodyparser
app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json())

//test
app.register = function(api) {
    api.get('id', getNextUserId);
    api.get('get_user_by_email', getUser);
   api.post('post_user', postUser)
}
3

3 Answers

1
votes

I don't recommend using Azure Mobile Services when combined with a Web App.

Create a regular Express based Web App. I use a Yeoman generator. Add the azure-mobile-apps package - this is middleware that provides the /tables endpoint for connecting to the SQL Azure instance. It also handles authentication and custom endpoint creation.

In this way, you do not need an extra service for handling mobile connections.

1
votes

The azure-mobile-apps module exposes a piece of middleware that you mount onto your express instance with the use function. The middleware handles particular routes such as /tables and /api.

You are able to mount any other middleware or routes you want onto your express app as well, leaving you free to use any prescribed "best practice" you see fit. To integrate into your sample:

var express = require('express');
var app = module.exports = express();
var bodyParser = require('body-parser');
var mobileApp = require('azure-mobile-apps')();

//configure bodyparser
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());

//configure mobile apps
mobileApp.tables.add('table');
app.use(mobileApp);

//test
app.register = function(api) {
    api.get('id', getNextUserId);
    api.get('get_user_by_email', getUser);
    api.post('post_user', postUser);
};
0
votes

Actually, the structure of Mobile Service is a little complicated. And we can do limited custom operations on its structure.

It is not quite clarified of your requirements. Will you want to implement custom APIs on mobile service or you want to implement an entire expressjs based backend server for your mobile applications?

And if you want to define multiple routes in a custom API script, you don't need to implement the entire expressjs structure, you only need to define all the routes functions and require dependencies in this script. Then the Mobile Service backend server start, it will scan the scripts in custom API folder and register the routes. You can refer to https://azure.microsoft.com/en-us/documentation/articles/mobile-services-how-to-use-server-scripts/#api-routes for more details.

And if you need extra modules for custom APIs using, you can leverage git to share and manage the custom scripts and dependencies. But you still don't need to implement the entire expressjs framework.

You can sign in the KUDU console site of your mobile service, to glance the entire structure and source code of your mobile service. And the scripts we managed are laying in App_Data folder.

Meanwhile, if you want to implement an entire expreejs based application as the backend server for your mobile applications, you can leverage the Azure Mobile Apps, refer to https://azure.microsoft.com/en-us/documentation/articles/app-service-mobile-node-backend-how-to-use-server-sdk/ for more info.