question

RogerHopkins-7069 avatar image
0 Votes"
RogerHopkins-7069 asked Bruce-SqlWork answered

HTTP Error 404.0 - Not Found running Node Express api from virtual application

I'm trying to deploy multiple Nodejs + Express API's from subfolders/virtual applications under one App Service.

For those that are wondering why: We have one custom domain for a set of API's. There is one common API that all apps will use and separate API's to/from different service providers.

The url's would be something like https://mydomain.com/common, https://mydomain.com/app1, etc.

I've spent the last several days researching this Q&A, MSDN blogs and Stack Overflow and trying multiple solutions with no success.

Here's what I've tried/accomplished:

  • Created an App Service with a subfolder/virtual application named app1

  • Deployed a simple Node http api (following the Node.js web app quick start) to the wwwroot\app1 subfolder/virtual application called the api from Postman - successful

  • Deployed a simple Node/Express api to the wwwroot folder and called the api from Postman - successful

  • Deployed the same Node/Express api to the wwwroot\app1 sub-folder and called the api from Postman . I first deleted all of the files from wwwroot to make sure there were no overlaps. - Received error 404.

Detailed Error Information:
Module iisnode
Notification ExecuteRequestHandler
Handler iisnode
Error Code 0x00000000
Requested URL https://cpr-node-test:80/common/index.js
Physical Path C:\home\site\wwwroot\common\index.js
Logon Method Anonymous
Logon User Anonymous

Here is my index.js code:
const express = require('express');
const app = express();

const host = process.env.WEBSITE_HOSTNAME
const port = process.env.PORT || 1337;

app.get('/', (req, res) => res.send(`App1 host ${host} listening on port ${port}!`));
app.listen(port, () => console.log(`Example app1 host ${host} llistening on port ${port}!`));

Here is my web.config file:

<?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>
<handlers>
<add name="iisnode" path=".js" verb="" modules="iisnode" />
</handlers>
<rewrite>
<rules>

                 <!-- Don't interfere with requests for node-inspector debugging -->
                 <rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">                    
                      <match url="^index.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 application entry point -->
                 <rule name="DynamicContent">
                      <conditions>
                           <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True"/>
                      </conditions>
                      <action type="Rewrite" url="index.js"/>
                 </rule>

            </rules>
       </rewrite>

       <iisnode watchedFiles="*.js;node_modules\*;routes\*.js;views\*.jade"/>
       <directoryBrowse enabled="true"/>
  </system.webServer>

</configuration>

I'd appreciate any help I can get. Thanks

windows-server-iis-generalwindows-server-iis-platform
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Correction to the above:
wwwroot\app1 subfolder should read wwwroot/common

0 Votes 0 ·

@RogerHopkins-7069 You can use failed request tracking to view detailed error information, this will help analyse the root cause.


0 Votes 0 ·
RogerHopkins-7069 avatar image
0 Votes"
RogerHopkins-7069 answered

Thank you. I read these articles before and they require a Windows PC.

I have a Macbook running OS X. Is there an alternative?

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Bruce-SqlWork avatar image
0 Votes"
Bruce-SqlWork answered

On a macOS you use launchd to start the node projects with different ports. Then use Apache or ngnix to reverse proxy to the node sites. The url rewrite rules are similar. See the docs for the proxy you pick.

Google for lots of examples

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.