在本地运行Azure Node.js应用-连接到同一数据库

在本地运行Azure Node.js应用-连接到同一数据库

问题描述:

是否可以在本地运行Azure Node.js应用服务,但连接到相同的云SQL数据库?

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

如果是这样,那么在连接到本地运行的服务时,如何将客户端连接到本地服务?假设客户端通过HTML/javascript应用程序进行连接,则正常代码为client = new WindowsAzure.MobileServiceClient('https://myservice.azurewebsites.net');<-您是否只是将URL更改为运行本地服务器的IP?

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?

是的,可以在本地运行Azure移动应用.

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

您只需要将存储库从Azure拖到本地,然后在根文件夹(包括package.json文件)下运行npm install命令.在安装所有npm软件包之后,您应该运行以下命令来启动本地Node.js服务器:

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');

,然后从index.html更改CSP HTTP标头:

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 *">

有关更多信息,请参阅 https://shellmonger.com/2016/04/01/30-days-of-zumo-v2-azure-mobile-apps-day-2-local-development/

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