2017-10-07 96 views
0

我有一個index.html頁面,用於我想要使用的Azure Mobile app而不是顯示「此移動應用程序已啓動並正在運行」的默認藍色網頁。我把index.html放在wwwroot文件夾中,並在app.js中將homePage值設置爲false適用於Azure移動應用程序的index.html

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

但是不提供頁面。我得到了一個空白頁面,該文本而不是

Cannot GET/

還有什麼我需要以有我的行動應用程式進行提供靜態HTML & JS網頁?

回答

1

將app.js中的代碼替換爲下面的代碼。

  1. 您需要告訴服務器使用來自特定文件夾(此處爲公共)的靜態文件。將您的索引文件放在公用文件夾內。
  2. 然後,您需要在調用應用程序的根時返回文件。

    mobileApp.tables.initialize() 
    .then(function() { 
        app.use(mobileApp); // Register the Azure Mobile Apps middleware 
        app.listen(process.env.PORT || 3000); // Listen for requests 
    
        //Need to add below 2 lines 
        app.use(express.static('public')); 
        app.get('/',function(req,res){ 
         res.sendFile('index.html'); 
        }); 
    }); 
    
+0

完美!謝謝。 –

相關問題