2

I have a fairly standard node app deployed to Azure. By default, for a request of http:www.example.com/my_path Azure adds a web.config xml file to set up IIS so it will:

a) see if a static file matching /my_path exists in the /public folder
b) route all other requests to the nodejs app.

That's close to what I want, except that for the root path (http:www.example.com/) I want it to just display public/index.html, and at the moment it routes the root path to the node app.

I'm unable to get it to do that. Here's the relevant section from my web.config:

<!-- 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"/>
    <!-- WHAT SHOULD THIS NEXT LINE BE TO IGNORE THE BASE PATH
    FROM THIS RULE TO SEND REQUESTS TO THE NODE APP? -->
    <add input="{REQUEST_URI}" pattern="^$" negate="True"/>
  </conditions>
  <action type="Rewrite" url="server.js"/>
</rule>
4
  • Spend some time on IIS.net's related pages. It shows so many examples and you should be able to learn how to use it instead of relying on others. Commented Aug 25, 2016 at 10:42
  • @LexLi If it was you who voted to close this question, could you help me understand why? I feel like I've asked a specific question about programming, which has a clearly defined answer. In what way is this "off topic" for stackoverflow? Thanks. Commented Aug 25, 2016 at 11:09
  • IIS configuration questions belong to ServerFault if you don't know before. Commented Aug 25, 2016 at 12:03
  • ~25k IIS questions on Stackoverflow would indicate otherwise: stackoverflow.com/questions/tagged/iis Commented Aug 25, 2016 at 12:05

1 Answer 1

1

You can try to add & modify the following rewrite content in web.config file:

<rule name="SpecificRedirect" stopProcessing="true">
    <match url="/" />
    <action type="Rewrite" url="/index.html" />
</rule>
<!-- All other URLs are mapped to the node.js site entry point -->
<rule name="DynamicContent">
    <match url="/api" />
     <conditions>
          <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True"/>
     </conditions>
     <action type="Rewrite" url="app.js"/>
</rule>

If the request matches the url yourdomain, it will rewrite the index.html in your root directory, and stop the rewirte process which present the index.html request be routed by node.js applicatio.

And also which configure the node.js application to handle the requesting in sub pattern /api.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.