【问题标题】:Hosting a sub ASP application in a nodejs express application in azure在 azure 的 nodejs express 应用程序中托管子 ASP 应用程序
【发布时间】:2020-10-01 16:40:36
【问题描述】:

Q1) 我的主应用程序是用 nodejs express 构建的。我有一个使用 asp.net 制作的子应用程序,我想将它作为一个虚拟应用程序托管在我的主应用程序中。有什么办法可以做到吗?

目前,我的 nodejs 正在将调用 https://localhost:5000/mysite1 视为目录并给出 404 错误。

我的文件夹结构看起来像...

index.html
server.js
scripts
web.config (*)
----- mysite1
      |----- bin
      |----- Controllers
      |----- Pages
      |----- Scripts
      |----- web.config (**)

Q2 从长远来看,我想将应用程序带到 Azure 应用程序服务并在那里托管。运行时堆栈将是 Node 12 LTS。这在 Azure 中可行吗?

我的 nodejs 应用程序的 web.config 文件。

<?xml version="1.0" encoding="utf-8"?>
<!--
     This configuration file is required if iisnode is used to run node processes behind
     IIS or IIS Express.  For more information, visit:

     https://github.com/tjanczuk/iisnode/blob/master/src/samples/configuration/web.config
-->

<configuration>
  <system.webServer>
    <!-- Visit http://blogs.msdn.com/b/windowsazure/archive/2013/11/14/introduction-to-websockets-on-windows-azure-web-sites.aspx for more information on WebSocket support -->
    <webSocket enabled="false" />
    <handlers>
      <!-- Indicates that the server.js file is a node.js site to be handled by the iisnode module -->
      <add name="iisnode" path="server.js" verb="*" modules="iisnode"/>
    </handlers>
    <rewrite>
      <rules>
        <!-- Do not interfere with requests for node-inspector debugging -->
        <rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">
          <match url="^server.js\/debug[\/]?" />
        </rule>

        <!-- Do not interfere with requests for node-inspector debugging -->
        <rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">
          <match url="^cot" />
        </rule>

        <!-- 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="server.js"/>
        </rule>
      </rules>
    </rewrite>
    
    <!-- 'bin' directory has no special meaning in node.js and apps can be placed in it -->
    <security>
      <requestFiltering>
        <hiddenSegments>
          <remove segment="bin"/>
        </hiddenSegments>
      </requestFiltering>
    </security>

    <!-- Make sure error responses are left untouched -->
    <httpErrors existingResponse="PassThrough" />

    <!--
      You can control how Node is hosted within IIS using the following options:
        * watchedFiles: semi-colon separated list of files that will be watched for changes to restart the server
        * node_env: will be propagated to node as NODE_ENV environment variable
        * debuggingEnabled - controls whether the built-in debugger is enabled

      See https://github.com/tjanczuk/iisnode/blob/master/src/samples/configuration/web.config for a full list of options
    -->
    <!--<iisnode watchedFiles="web.config;*.js"/>-->
    
    <staticContent>
      <remove fileExtension=".json"/>
      <mimeMap fileExtension=".json" mimeType="application/json"/>
    </staticContent>
  </system.webServer>
</configuration>

更新

Server.js 路由

..
....
app.use(express.static(path.join(__dirname, 'public')));
app.use('/', indexRouter);
app.use('/users', usersRouter);
app.use('/auth', authRouter);  
....
..

【问题讨论】:

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


    【解决方案1】:

    虚拟应用程序目录结构应如下所示。

    wwwroot
      |----- index.html
      |----- server.js
      |----- scripts
      |----- web.config (*)
    mysite1
      |----- bin
      |----- Controllers
      |----- Pages
      |----- Scripts
      |----- web.config (**)
    

    更多详情,您可以在下面的帖子中查看我的答案。

    How to deploy a Flask+React application to Azure Web Service

    React.js - How to deploy client and server independently or together?

    【讨论】:

    • 我尝试执行上述结构,但我的 server.js 正在获取对 mysite1 的所有调用。所以我猜我必须更改我的 web.config 或 server.js 中的某些内容才能允许这种情况发生?我在 server.js 中提供了我的路由的 sn-p
    • @user7278236 你应该使用virtual 路径来发送你的http请求。这是另一个问题。你可以谷歌一下。
    猜你喜欢
    • 2017-05-07
    • 1970-01-01
    • 1970-01-01
    • 2021-04-10
    • 1970-01-01
    • 2014-12-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多