node js azure error accessing routes - node.js

I have a node js application that works fine in my localhost and in AWS. I deployed it to Azure with the following web.config file in the root of the directory:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="iisnode" path="index.js" verb="*" modules="iisnode" />
</handlers>
<iisnode nodeProcessCountPerApplication="4" />
</system.webServer>
</configuration>
In addition, I have a file iisnode.yml, also at the root of directory, with the line:
nodeProcessCountPerApplication: 4
The root directory contains a file index.js which is the entry point to the application, and it is configured to run an express app on port process.env.PORT || 1337. In package.json, the start command is node index.js.
The application gets deployed, but for every route I try to run I see the following error:
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.

Please try to add the rewrite mode in the web.config file, beside the handlers tag under system.webServer tag:
<rewrite>
<rules>
<rule name="DynamicContent">
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True"/>
</conditions>
<action type="Rewrite" url="index.js"/>
</rule>
</rules>
</rewrite>
Any update, please feel free to let me know.

Related

403 when trying to deploy a Node app to IIS

Inside this directory is my Node app: /wwwroot/poldeb/internal_affairs_incident_reporter
My app is running on port 8080.
In IIS, this is my configuration:
I can get to www.poldeb.com fine because I have a static HTML page there, but when I try to get to www.poldeb.com/IAIR where my Node.js app should be running, I get a 403 error. How do I access my Node.JS app from this subdomain?
I got through this error by refactoring my IIS structure. I made IAIR its own website and gave it the subdomain iair.poldeb.com. Inside of IAIR, this was my web.config:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="iisnode" path="app.js" verb="*" modules="iisnode" />
</handlers>
<rewrite>
<rules>
<rule name="sendToNode">
<match url="/*" />
<action type="Rewrite" url="app.js" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
I also had to give write access to the user IIS_IUSRS for the internal_affairs_incident_reporter directory.

Deploying server-side NodeJS app on Windows-based Azure App Service (CI/CD Using Azure DevOps)

Our use case consists of the following aspects:
Ci/CD Using Azure Devops in order to ensure automation and monitoring.
Azure AppService based on windows
Our React projects consists of: Frontend asking a server-side script (server.js) for a url to embed.
server.js performs some authentications and modifications and returns a single url "live" for a specific period of time.
Running on local station using npm start and starting the server using node of course works perfectly.
But when deploying to a windows-based AppService, I cant see how to start the server.js.
My CI is npm installing and ZIPing the artifact.
CD is deploying the artifact and serving the index.js web page.
But I cant seem to see how to start the server.js file.
Feels like I am missing some important piece regarding IIS and web.config
you could try to add the below code in your web.config file:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<webSocket enabled="false" />
<handlers>
<add name="iisnode" path="server.js" verb="*" modules="iisnode"/>
</handlers>
<rewrite>
<rules>
<rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">
<match url="^server.js\/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="server.js"/>
</rule>
</rules>
</rewrite>
<security>
<requestFiltering>
<hiddenSegments>
<remove segment="bin"/>
</hiddenSegments>
</requestFiltering>
</security>
<httpErrors existingResponse="PassThrough" />
</system.webServer>
</configuration>

Trying to run a Node app from sub-directory in App Service serves server.js file

I have a strange issue trying to run a Node app in a sub-directory on an Azure App Service.
My directory structure is:
|common
-- common_model.js
|client
-- angular 2 app js files
|server
-- server.js with other express app files
|web.config
I've configured the web.config file to point all requests to the server\server.js file:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<webSocket enabled="false" />
<handlers>
<add name="iisnode" path="server\server.js" verb="*" modules="iisnode"/>
</handlers>
<rewrite>
<rules>
<rule name="DynamicContent">
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True"/>
</conditions>
<action type="Rewrite" url="server\server.js"/>
</rule>
</rules>
</rewrite>
<security>
<requestFiltering>
<hiddenSegments>
<remove segment="bin"/>
<add segment="node_modules" />
</hiddenSegments>
</requestFiltering>
</security>
<httpErrors existingResponse="PassThrough" />
<iisnode watchedFiles="web.config;*.js"/>
</system.webServer>
</configuration>
When loading up the site in a browser, the content of server.js is returned and is not executed. What else might I need other than the iisnode handler configured to make this run?
Despite setting the path:
<add name="iisnode" path="server\server.js" verb="*" modules="iisnode"/>
The iisnode module seem to only function with the server.js file in the root. The solution is luckily simple enough, just create a server.js file in the root that simply includes the sub-directory file. The whole file is one line:
require("./server/server.js");
Then you can use the default iisnode handler:
<add name="iisnode" path="server.js" verb="*" modules="iisnode"/>

Yeoman angular project in Azure web app

I am using generator to create a angular projects:
https://github.com/yeoman/generator-angular
Loading the website give me this error:
You do not have permission to view this directory or page.
I added iinode web.config:
<handlers>
<add name="iisnode" path="app.js" verb="*" modules="iisnode"/>
</handlers>
<rewrite>
<rules>
<rule name="DynamicContent">
<match url="/*" />
<action type="Rewrite" url="app.js"/>
</rule>
</rules>
</rewrite>
It has a grunt file and doesn't have server.js or app.js as start. How do I go about it?
iisnode will pick app.js or server.js at the root directory (wwwroot) by default. You can override this in web.config. Even you are using grunt, your app should have an entry file somewhere . Say it is at path bin/www/youApp.js, then you can tell iisnode to where to start the app by
<add name="iisnode" path="bin/www/youApp.js" verb="*" modules="iisnode"/>
You can solve it by telling where is the application folder:
Adding a file called .deployment.
Add the below to the .deployment:
[config]
project = app

Sails looking in wrong directory

I'm new to sails.js and node.js, so the question might be trivial, but I couldn't find the answer. I have deployed my node.js app to a web site in IIS, so the app can be reached at http://example.com/myapp/. When browsing to http://myhost.com/myapp/app.js, I get http status 404 (Not found), because sail.jss is looking for URLs like http://myhost.com/images/logo.png, but this file is in fact located at http://myhost.com/myapp/.tmp/public/images/logo.png. This .tmp folder seems to be created on the fly by the framework.
Can someone shed some light on this?
[edit]
I have added rewrite rules in the web.config and it works much better. But it only works if I put the application at the root of my web site (acessing http://myhost.com/). If I put the application in a lower level (accessing through http://myhost.com/myApp), then the added rules do not seem to produce any effect.
Here is the web.config:
<handlers>
<add name="iisnode" path="app.js" verb="*" modules="iisnode" />
</handlers>
<rewrite>
<rules>
<rule name="StaticContent">
<action type="Rewrite" url="assets{REQUEST_URI}"/>
</rule>
<rule name="DynamicContent">
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True"/>
</conditions>
<action type="Rewrite" url="app.js"/>
</rule>
</rules>
</rewrite>
The key is to allow Express to handle all of the routing. The best way to do that is to route all traffic to app.js via iisnode (from: https://nodestream.wordpress.com/2015/11/24/sails-js-configuration-for-iis/):
<configuration>
<system.webServer>
<!-- Tell IIS to use the iisnode module to run your
application -->
<handlers>
<add name="iisnode" path="app.js" verb="*" modules="iisnode" />
</handlers>
<!-- Add iisnode with the #nodeProcessCommand line if
you see the error: Make sure the node.exe executable
is available at the location specified in the
system.webServer/iisnode/#nodeProcessCommandLine element
of web.config. -->
<iisnode
nodeProcessCommandLine="%ProgramFiles%\nodejs\node.exe"
/>
<!-- Since behind the covers, Sails.js is just an express app
rewrite all urls to processed by iisnode via app.js. This
will sort out things like the routing to your public
resources (images, js, styles) and all configured rest
endpoints. -->
<rewrite>
<rules>
<rule name="root">
<match url=".*" />
<action type="Rewrite" url="app.js" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Well the .tmp folder is created by Grunt. You can reference the gruntfile and the task folder. The pipeline.js allows you to select files/folders for grunt to inject and spit out. You can easily change this to point to /images and /js folders.
tasks/pipline.js
module.exports.cssFilesToInject = cssFilesToInject.map(function(path) {
return '.tmp/public/' + path; // Change this
});
module.exports.jsFilesToInject = jsFilesToInject.map(function(path) {
return '.tmp/public/' + path; // Change this
});
Another solution I could think of, however I am not sure if IIS has it, is to do a rewrite rule. When a user goes to site.com/images, point them to .tmp/public/images. It is common to see that in Apache servers.

Resources