从外部Node进程连接到Azure Web应用程序/ SQL数据库

Connecting to Azure Web App / SQL Database from external Node process

本文关键字:应用程序 SQL 数据库 Web Azure Node 进程 连接 从外部      更新时间:2023-09-26

我有一个Azure Web应用程序正在运行,它定义了自定义的Easy api和一些Easy Tables。在过去的一年里,我一直在使用这个Azure Web应用程序和连接到它的SQL表来运行一些基于javascript的LOB Windows Store应用程序,它运行得非常好。

但是现在我需要访问这些资源为一个Node.js进程,我将在本地运行。我希望访问它的方式和我在Windows Store中访问它的方式差不多

var client = new window.WindowsAzure.MobileServiceClient(
      "https://my-mobileservice.azure-mobile.net/",
      "MOBILESERVICEKEY"
);

如果我不能使用上面提供的API从Node中访问Web应用程序,如果我可以手动读取和写入SQL表就足够了。

我该怎么做呢?

您提供的代码片段使用Azure Mobile Apps客户端SDK,该SDK适用于设备或浏览器。

在你的其他node.js应用程序中,你可以考虑对你的Easy Tables和Easy api脚本实现HTTP请求。因为Azure移动应用服务已经将它们公开为RESTful api。您可以参考https://azure.microsoft.com/en-us/documentation/articles/app-service-mobile-node-backend-how-to-use-server-sdk/#TableOperations获取更多信息。

您可以参考下面的代码片段获取信息。

var request = require("request");
request({
    method:'GET',
    url:'https://<your_mobile_app>.azurewebsites.net/tables/TodoItem',
    headers:{
        'ZUMO-API-VERSION':'2.0.0'
    }
},(err,res,body)=>{
    console.log(body);
})