适用于Azure移动应用程序的index.html
问题描述:
我有一个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网页?
答
将app.js中的代码替换为下面的代码。
- 您需要告诉服务器使用来自特定文件夹(此处为公共)的静态文件。将您的索引文件放在公用文件夹内。
-
然后,您需要在调用应用程序的根时返回文件。
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'); }); });
完美!谢谢。 –