locked
Azure nodejs web app custom domain subdirectory to another azure web app(blog) RRS feed

  • Question

  • I have simple Node.js Webapp with custom domain ex: domain.com.

    I have created another azure cloudapp from bitnami and mapped it to blog.domain.com

    Now, I would like to have a blog path domain.com/blog which should serve the blog from blog.domain.com

    As I researched, I have added a blog route in server.js and a rule in my web.config but its not working.

    Server.js

    const express = require('express');
    const port = process.env.PORT || 1337;
    const app = express();
    const path = require('path');
    const router = express.Router();
    
    router.get('/',(req,res) => {
      res.sendFile(path.join(__dirname +  '/public/index.html'));
    });
    
    router.get('/blog',(req,res) => {
      res.sendFile(path.join(__dirname + '/public/blog.html'));
    });
    
    app.use(express.static(__dirname + '/public'));
    app.use('/', router);
    
    app.listen(port);

    <configuration>
      <system.webServer>
        <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>
    
            <!-- 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> -->
            <rule name="blogRedirect" stopProcessing="true" enabled="true"> 
                <match url="^blog" />
                <conditions>
                    <add input="{HTTP_HOST}"/>
                </conditions>
                <action type="Redirect" url="https://mathan.azurewebsites.net/hello" />
            </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>
    
        <httpErrors existingResponse="PassThrough" />
      </system.webServer>
    </configuration>

    Can someone guide me what's wrong with the things I did?

    Tuesday, March 31, 2020 6:44 AM

All replies

  • Hi Dinesh,

    Could you provided any errors that you're getting? Your redirection action appears it's going to /hello which isn't a route rather than /blog. Not sure if that was a type or not. If you haven't already, you can enable application logging you can get better insights into the HTTP traffic. Feel free to share any diagnostics logs.

    Furthermore, We're migrating from MSDN to Microsoft Q&A as our new forums and Web Apps which is your question is more closely related to has already made the move! In future, you can ask and look for the discussion for Web App related questions here: https://docs.microsoft.com/answers/topics/azure-webapps.html. We are actively working to onboard remaining Azure services on Microsoft Q&A and we will make a public announcement once complete. Want to Learn more about new platform: Microsoft Q&A Getting Started.


    Thanks in advance, Ryan

    Tuesday, March 31, 2020 1:27 PM