gpt4 book ai didi

node.js - 设置根路径以在 Azure(IIS Web 服务器)上提供 index.html

转载 作者:太空宇宙 更新时间:2023-11-03 22:12:12 25 4
gpt4 key购买 nike

我有一个相当标准的 Node 应用程序部署到 Azure。默认情况下,对于 http:www.example.com/my_path 的请求,Azure 会添加一个 web.config xml 文件来设置 IIS,这样它将:

a) 查看 /public 文件夹中是否存在与 /my_path 匹配的静态文件
b) 将所有其他请求路由到 Nodejs 应用程序。

这接近我想要的,除了根路径(http:www.example.com/)我希望它只显示public/index.html,目前它将根路径路由到 Node 应用程序。

我无法让它做到这一点。这是我的 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"/>
<!-- WHAT SHOULD THIS NEXT LINE BE TO IGNORE THE BASE PATH
FROM THIS RULE TO SEND REQUESTS TO THE NODE APP? -->
<add input="{REQUEST_URI}" pattern="^$" negate="True"/>
</conditions>
<action type="Rewrite" url="server.js"/>
</rule>

最佳答案

您可以尝试在web.config文件中添加和修改以下重写内容:

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

如果请求与yourdomain url匹配,它将重写根目录中的index.html,并停止显示index.html的重写过程。 html 请求由 Node.js 应用程序路由。

并且还配置node.js应用程序以处理子模式/api中的请求。

关于node.js - 设置根路径以在 Azure(IIS Web 服务器)上提供 index.html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39140090/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com