【问题标题】:Node.js Route not working on Microsoft AzureNode.js 路由在 Microsoft Azure 上不起作用
【发布时间】:2018-10-19 03:56:30
【问题描述】:

您好,我构建了一个非常基本的 Node.js 应用程序(没有任何框架), 我设置了一条路线。 index.html 和 login.html

在我的本地机器(Windows 10)上它工作正常。当我从 url 调用它们时,两个文件 index.html 和 login.html 都会显示在浏览器中。喜欢

localhost/myapp => 加载 index.html localhost/myapp/login => 加载 login.html

现在我将它部署在 Microsoft Azure 上,现在只加载索引文件,当我尝试加载 myapp.azurewebsites.net/login 时,它说:您要查找的资源已被删除,有名称已更改,或暂时不可用。

我有一个包含这些设置的 web.config 文件

<?xml version="1.0"?>
<configuration>
<system.webServer>
     <staticContent>
     <mimeMap fileExtension=".html" mimeType="text/html" />
  </staticContent>
</system.webServer>
</configuration>

请指导我如何在 azure 上的 node.js 中启用路由。没有任何框架。官方文档没有帮助。

谢谢

【问题讨论】:

    标签: node.js azure azure-web-app-service


    【解决方案1】:

    经过大量搜索,我找到了解决方案。 您需要从他们的演示项目中设置 web.config 文件并上传到您自己的 azure 项目中。 https://github.com/Azure-Samples/nodejs-docs-hello-world/archive/master.zip

    【讨论】:

      【解决方案2】:

      您可以使用 Azure Node JS Starter Site 或 Node JS Empty Web App。

      在这些项目中,您将找到在 Azure 中运行 Node 应用程序所需的正确 web.config 文件。

      【讨论】:

        【解决方案3】:

        尝试在 web.config 文件中添加以下代码,看看是否有效。

        <configuration>
        <system.webServer>
            <rewrite>
              <rules>
                <rule name="Main Rule" stopProcessing="true">
                        <match url=".*" />
                        <conditions logicalGrouping="MatchAll">
                            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                        </conditions>
                        <action type="Rewrite" url="/" />
                    </rule>
                </rules>
            </rewrite>
        </system.webServer>
        </configuration>
        

        有关此错误的更多详细信息,请关注link

        【讨论】:

        • 无论我选择什么路线,您的代码都会将我重定向到 index.html
        • 您是指将一个页面导航到另一个页面吗?请点击下面的链接,这可能会有所帮助。 stackoverflow.com/questions/33720267/…
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-05-16
        • 1970-01-01
        • 2019-10-09
        • 2017-04-29
        • 2021-02-02
        • 2019-08-28
        • 1970-01-01
        相关资源
        最近更新 更多