简体   繁体   中英

Running Azure Node.js app locally - connecting to same database

Is it possible to run an Azure Node.js App Service locally, but connect to the same cloud SQL database?

If so, when connecting to the locally running service, how do you connect a client to the local service? Assuming a client is connecting via an HTML/javascript app, the normal code would be client = new WindowsAzure.MobileServiceClient('https://myservice.azurewebsites.net'); <-- do you just change that url to the IP the local server is running on?

Yes, it is possible to get an Azure Mobile App running locally.

You just need to pull the repo from Azure to your local, and then run npm install command under the root folder (which includes package.json file). After all npm packages are installed you should run the following command to start the local Node.js server:

set SQLAZURECONNSTR_MS_TableConnectionString=<mssql_connection_string>&& node app.js

Now, on the client side, change your connection reference to something like this:

client = new WindowsAzure.MobileServiceClient('http://localhost:3000');

and change the CSP HTTP header as below from the index.html :

<meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: http://localhost:3000; style-src 'self'; media-src *">

For more information, please refer to https://shellmonger.com/2016/04/01/30-days-of-zumo-v2-azure-mobile-apps-day-2-local-development/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM