0

Q1) I have my main app built with nodejs express. I have a sub-app made using asp.net and I want to host that as a virtual application within my main app. Is there any way I can do this?

Currently, my nodejs are treating the call https://localhost:5000/mysite1 as a directory and giving a 404 error.

My folder structure looks like...

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

Q2 In the long run, I'd like to take the app to Azure App Services and host it there. The runtime stack would be Node 12 LTS. Is this possible in Azure?

My web.config file for nodejs app.

<?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>

Update

Server.js routing

..
....
app.use(express.static(path.join(__dirname, 'public')));
app.use('/', indexRouter);
app.use('/users', usersRouter);
app.use('/auth', authRouter);  
....
..
saf1
  • 960
  • 3
  • 9
  • 21

1 Answers1

0

The virtual application directory structure should look like this.

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

For more details, you can check my answer in below post.

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

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

Jason Pan
  • 15,263
  • 1
  • 14
  • 29
  • I tried doing the above structure but my server.js was getting all the calls being made to mysite1. So i'm guessing I have to change something in my web.config or in my server.js to allow that to happen? I've provided a snippet of my routes in server.js – saf1 Oct 14 '20 at 09:08
  • @user7278236 You should use `virtual` path to send your http request. And this is another question. You can google it. – Jason Pan Oct 14 '20 at 09:14