Azure Websites + node.js - Cannot GET /

3

When deploying a node.js / express app to Azure Websites I am getting "Cannot GET /" error in the browser. The same application runs flawlessly on the local machine.

web.config is standard (I only removed the Static Rewrite rule), so:

    <!-- 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="src/server/app.js"/>
    </rule>
  </rules>

Code is deployed in src/server/ (node functions) and src/client/ (static content) folders.

As per the FREB logs the src/server/apps.js is fetched, but in the end the following error is thrown:

ErrorCode   The system cannot find the file specified.     (0x80070002)

Inside app.js I have the following configuration for static files:

   app.use(express.static('./src/client/'));
node.js
azure-web-app-service
asked on Stack Overflow Feb 2, 2017 by Lech Migdal

1 Answer

1

Azure Websites runs node from the folder where the file defined in the package json as the start file is located, so e.g. for the following:

"start": "node src/server/app.js"

fact it will run node app.js from the src/server folder (you can find there also the iisnode.yml file). Which results in all relative paths getting messed up. One solution for this is to use absolute paths, so e.g.:

app.use(express.static('D:/home/site/wwwroot/src/client/'));

and switching between paths using e.g. process.env.NODE_ENV variable.

answered on Stack Overflow Feb 2, 2017 by Lech Migdal

User contributions licensed under CC BY-SA 3.0