我有一个现有的Azure App Service移动应用程序。它适用于iOS和Android客户端(和外部网站)。我的理解是,所有App Service选项本质上都是同一产品,并应用了不同的默认模板,因此我想将自己的一些网页添加到此Mobile App中。
我创建了一个测试/示例Web App,在App Service编辑器中,该wwwroot
文件夹中似乎只有一个文件:hostingstart.html
。(有趣的是,甚至没有web.config
。为什么呢?)
在我的Node.js移动应用程序上,当然有一个很大的文件夹结构,看起来像这样(一些项目被省略了):
我曾尝试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
退货:
当我的一种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>
我假设我需要在此处进行一些更改以允许访问,但是那又是什么呢?
有趣的是,甚至没有
web.config
。这是为什么?
按我的经验,如果app.js
/ server.js
/index.js
包含在wwwroot
文件夹中,然后Azure的应用服务会认为它是一个应用程序的Node.js并自动生成的web.config。
我假设我需要在此处进行一些更改以允许访问,但是那又是什么呢?
我认为您无需在此处进行任何更改。根据web.config中的以下行。您可能需要考虑将您的静态文件(例如html,js,css等)放在/public
下方的文件夹中wwwroot
。
<!-- 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>
您还可以通过Express通过以下代码执行相同的操作,
app.use(express.static('public'))
实际上,Azure Mobile Apps
Node.js SDK是一个express
中间件软件包,可轻松为您的移动应用程序创建后端并使它在Azure上运行。中间件处理诸如/tables
和的特定路由/api
。同时,您还可以将任何其他所需的中间件或路由安装到Express应用程序上,从而可以自由使用任何您认为合适的规定“最佳实践”。
如有任何其他疑问,请随时告诉我。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句