2016-12-03 145 views
1

我有一個現有的Azure應用程序服務移動應用程序。它適用於iOS和Android客戶端(以及外部網站)。我的理解是,所有應用服務選項基本上都是應用不同默認模板的相同產品,所以我想將我自己的一些網頁添加到此移動應用。將網站添加到現有的Azure移動應用程序(應用程序服務)

我創建了一個測試/示例Web App,並且在App Service編輯器中,wwwroot文件夾中似乎只有一個文件:hostingstart.html。 (有趣的是,甚至沒有web.config這是爲什麼?)

在我的Node.js移動應用程序,當然有一個大的文件夾結構,看起來像這樣(有些項目被忽略):

  • API(文件夾)
  • node_modules(文件夾)
  • 表(文件夾)
  • 分型(文件夾)
  • app.js
  • iisnode.yml
  • 的package.json
  • 的web.config

我嘗試添加一個index.html這個根(wwwroot)文件夾,但隨後導航到http://{service name}.azurewebsites.net/index.html只是給了我同樣的「這個服務已經像往常一樣創建「頁面。

所以,後來我走進我的app.js文件,並改變了這一點:

var mobile = azureMobileApps({ 
    // Explicitly enable the Azure Mobile Apps home page 
    homePage: true 
}); 

這樣:

var mobile = azureMobileApps({ 
    // Explicitly enable the Azure Mobile Apps home page 
    homePage: false 
}); 

之後,出現以下錯誤:

  • 導航到{service name}.azurewebsites.net退貨:
    • 不能得到/
  • 導航到{service name}.azurewebsites.net/index.html回報:
    • 不能得到/index.html

當我遇到這樣的錯誤了我的API方法之一,我檢查{api method}.json文件中的設置。我不認爲這是答案。

我猜測在某個文件中有某種開關允許直接提供*.html請求。我在我的web.config文件中的以下條目:

<!-- First we consider whether the incoming URL matches a physical file in the /public folder --> 
<rule name="StaticContent"> 
    <action type="Rewrite" url="public{REQUEST_URI}"/> 
</rule> 

<!-- All other URLs are mapped to the node.js site entry point --> 
<rule name="DynamicContent"> 
    <conditions> 
    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True"/> 
    </conditions> 
    <action type="Rewrite" url="app.js"/> 
</rule> 

我會承擔,我需要改變的東西在這裏允許訪問,但什麼?

+0

嗨@ mbm29414,還有更新嗎? –

回答

1

有趣的是,甚至沒有web.config。這是爲什麼?

按我的經驗,如果app.js/server.js/index.js包含在wwwroot文件夾,然後Azure的應用服務會認爲它是一個應用程序的Node.js並自動生成的web.config。

我假設我需要在這裏改變一些東西來允許 訪問,但是什麼?

我不認爲你需要改變這裏的東西。根據web.config中的以下行。您可能需要考慮將您的靜態文件(例如html,js,css等)放在wwwroot下的/public文件夾中。

<!-- First we consider whether the incoming URL matches a physical file in the /public folder --> 
<rule name="StaticContent"> 
    <action type="Rewrite" url="public{REQUEST_URI}"/> 
</rule> 

以下是我測試過的截圖。 enter image description here enter image description here

你也可以做同樣的事情用下面的代碼通過快遞,

app.use(express.static('public')) 

其實,Azure Mobile Apps Node.js的SDK是一個express中間件軟件包,可以很容易地創建一個後臺爲您的移動應用程序,並讓它在Azure上運行。中間件處理特定路線,如/tables/api。 同時,您也可以將任何其他中間件或路由安裝到您的快速應用程序中,讓您可以自由使用您認爲合適的任何規定的「最佳實踐」。

任何進一步的關注,請隨時感覺讓我知道。

相關問題