Search code examples
node.jsazureazure-web-app-servicevisual-studio-2017iisnode

Internal server error 500, hosting Node.js Express 4 application template from Visual Studio 2017 in Azure


I create a project from the project template: "Basic Azure Node.js Express 4 Application" in Visual Studio 2017 Enterprise edition.

enter image description here

When I run it locally it works fine. Now I publish this to Azure using the below Publish menu:

enter image description here

I get the following error:

iisnode encountered an error when processing the request.

HRESULT: 0x2
HTTP status: 500
HTTP subStatus: 1001
HTTP reason: Internal Server Error

enter image description here

I'm making no changes to the code from the template.

Any Ideas?


Solution

  • I followed your steps in Visual Studio 2017 Community edition. When I published the Express app to Azure Web App, I get the following error on my browser.

    The page cannot be displayed because an internal server error has occurred.

    After some investigation, I fixed it by changing the Web.config file to something like this:

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
    
      <system.webServer>
        <staticContent>
          <mimeMap fileExtension=".svg" mimeType="image/svg+xml" />
        </staticContent>
        <modules runAllManagedModulesForAllRequests="false" />
    
        <iisnode watchedFiles="web.config;*.js;routes\*.js;views\*.pug" />
    
        <handlers>
          <add name="iisnode" path="bin/www" verb="*" modules="iisnode" />
        </handlers>
    
        <rewrite>
          <rules>
            <rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">
              <match url="^bin/www\/debug[\/]?" />
            </rule>
            <rule name="StaticContent">
              <action type="Rewrite" url="public{REQUEST_URI}" />
            </rule>
            <rule name="DynamicContent">
              <conditions>
                <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True" />
              </conditions>
              <action type="Rewrite" url="bin/www" />
            </rule>
          </rules>
        </rewrite>
    
        <security>
          <requestFiltering>
            <hiddenSegments>
              <remove segment="bin" />
            </hiddenSegments>
          </requestFiltering>
        </security>
    
      </system.webServer>
    
    </configuration>    
    

    Also, the web.config file can be found at https://github.com/projectkudu/kudu/wiki/Using-a-custom-web.config-for-Node-apps.

    Hope this will help you.