0

I read that a deployment of many node.js applications in one azure web app is possible. So I wanted to try it. I created three node.js applications using express, and placed them as following:

TestApplication
    -testapp0
        node_modules
        index.js
        package.json
        package-lock.json
        web.config
    -testapp1
        node_modules
        index.js
        package.json
        package-lock.json
        web.config
    -testapp2
        node_modules
        index.js
        package.json
        package-lock.json
        web.config

Every index.js has almost the exact same code. The output is the only thing that changes. In the web.config I changed the names of the handlers and rules.

index.js

const express = require("express");
const app = express();


app.get("/", (_, res)=>{
    res.status(200).send("Welcome to TestApp0"); // testapp1: Welcome to TestApp1, testapp2: Welcome to TestApp2 
});
app.get("/test", (_, res)=>{
    res.status(200).send("TestApp0 TestPath"); //testapp1: TestApp1 TestPath, testapp2: TestApp2 TestPath
});

const PORT = process.env.PORT || 1337;
app.listen(PORT, () => console.log(`Listening to http://localhost:${PORT}`));

web.config

<?xml version="1.0" encoding="utf-8"?>

<configuration>
  <system.webServer>
    <webSocket enabled="false" />
    <handlers>
      <!-- name="iisnode1" for testapp1 and name="iisnode2" for testapp -->
      <add name="iisnode0" path="index.js" verb="*" modules="iisnode"/>
    </handlers>
    <rewrite>
      <rules>
        <!-- name="NodeInspector1" for testapp1 and name="NodeInspector2" for testapp -->
        <rule name="NodeInspector0" patternSyntax="ECMAScript" stopProcessing="true">
          <match url="^index.js\/debug[\/]?" />
        </rule>
        <!-- name="StaticContent1" for testapp1 and name="StaticContent2" for testapp -->
        <rule name="StaticContent0">
          <action type="Rewrite" url="public{REQUEST_URI}"/>
        </rule>
        <!-- name="DynamicContent1" for testapp1 and name="DynamicContent2" for testapp -->
        <rule name="DynamicContent0">
          <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True"/>
          </conditions>
          <action type="Rewrite" url="index.js"/>
        </rule>
      </rules>

    </rewrite>
    <security>
      <requestFiltering>
        <hiddenSegments>
          <remove segment="bin"/>
        </hiddenSegments>
      </requestFiltering>
    </security>
    <httpErrors existingResponse="PassThrough" />
  </system.webServer>
</configuration>

Once I had the code ready, I deployed the File TestApplication to Azure using the Azure App Service extension in VSCode.

Before that I took care to change the Settings of "Path Mapping":

| virtueller Pfad | Physischer Pfad       |     Typ     |
---------------------------------------------------------
|       /         | site\wwwroot\testapp0 | Application |
|  /testapp1      | site\wwwroot\testapp1 | Application |
|  /testapp2      | site\wwwroot\testapp2 | Application |

When I start the application I go, as desired, straight to testapp0 and when I enter the "/test" path, it shows me the desired output "TestApp0 TestPath".

I wanted to see in the screen the following:

"Welcome to TestApp0" when I go to "/"              it works
"TestApp0 TestPath"   when I go to "/test"          it works
"Welcome to TestApp1" when I go to "/testapp1"      instead I get "Cannot GET /testapp1"
"TestApp1 TestPath"   when I go to "/testapp1/test" instead I get "Cannot GET /testapp1/test"
"Welcome to TestApp2" when I go to "/testapp2"      instead I get "Cannot GET /testapp2"
"TestApp2 TestPath"   when I go to "/testapp2/test" instead I get "Cannot GET /testapp2/test"

I tried to look everywhere for a way to achieve this. But sadly I haven't found a solution that worked and there is not much literature that I can read.

I assume that this isn't working because the node application (testapp0) looks for a path that is called "/testapp1" and there isn't any. That is why I get the "Cannot get" Error. But I want to switch to the other node application (testapp1) as soon as I enter "/testapp1" and then with "/testapp1/test" get the desired output. What am I doing wrong? I haven't found anything helpful and I am new to Azure. That is why guidance would be appreciated.

Thank you for your time!

Javi
  • 461
  • 6
  • 11
  • Does this help https://stackoverflow.com/questions/62078305/multiple-nodejs-instance-on-azure-app-service ? – Apoorva Chikara Feb 18 '21 at 13:09
  • I saw it before but the explanation on how to specify a virtual Application is not so clear.. I don't know where can I specify that in Azure – Javi Feb 18 '21 at 13:16
  • https://carldesouza.com/configuring-virtual-applications-with-azure-app-services-and-apim/ - these are the steps to create virtual application in App Service. – Apoorva Chikara Feb 18 '21 at 13:20
  • thanks for the links but it didn't work. I did everything like the tutorial said and I still get the Cannot GET Error I don't know what am I doing wrong – Javi Feb 18 '21 at 13:45

0 Answers0