Azure node.js not receiving POST requests - node.js

I have an app that works locally but when I deploy it to azure POST requests receive a 404 response. Various answers suggest that I need to edit my web.config but I don't see what needs to be changed.
If it's relevant: My POSTs are to a path called /receive on the server, which should be handled by server.js
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your Node.js application, please visit
http://go.microsoft.com/fwlink/?LinkId=290972
-->
<configuration>
<appSettings>
<!--
<add key="StorageAccountName" value="" />
<add key="StorageAccountKey" value="" />
<add key="ServiceBusNamespace" value="" />
<add key="ServiceBusIssuerName" value="" />
<add key="ServiceBusIssuerSecretKey" value="" />
-->
</appSettings>
<system.webServer>
<!-- mimeMap enables IIS to serve particular file types as specified by fileExtension. -->
<staticContent>
<mimeMap fileExtension=".svg" mimeType="image/svg+xml" />
</staticContent>
<modules runAllManagedModulesForAllRequests="false" />
<!-- Web.Debug.config adds attributes to this to enable remote debugging when publishing in Debug configuration. -->
<iisnode watchedFiles="web.config;*.js" />
<!-- Remote debugging (Azure Website with git deploy): Comment out iisnode above, and uncomment iisnode below. -->
<!--<iisnode watchedFiles="web.config;*.js"
loggingEnabled="true"
devErrorsEnabled="true"
nodeProcessCommandLine="node.exe --debug"/>-->
<!-- indicates that the server.js file is a Node.js application
to be handled by the iisnode module -->
<handlers>
<add name="iisnode" path="server.js" verb="*" modules="iisnode" />
<!-- Remote debugging (Azure Website with git deploy): Uncomment NtvsDebugProxy handler below.
Additionally copy Microsoft.NodejsTools.WebRole to 'bin' from the Remote Debug Proxy folder.-->
<!--<add name="NtvsDebugProxy" path="ntvs-debug-proxy/eee3ec35-9835-494f-a07c-dc2f85619df0" verb="*" resourceType="Unspecified"
type="Microsoft.NodejsTools.Debugger.WebSocketProxy, Microsoft.NodejsTools.WebRole"/>-->
</handlers>
<rewrite>
<rules>
<clear />
<!-- Remote debugging (Azure Website with git deploy): Uncomment the NtvsDebugProxy rule below. -->
<!--<rule name="NtvsDebugProxy" enabled="true" stopProcessing="true">
<match url="^ntvs-debug-proxy/.*"/>
</rule>-->
<!-- Don't interfere with requests for node-inspector debugging -->
<rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">
<match url="^server.js\/debug[\/]?" />
</rule>
<rule name="app" enabled="true" patternSyntax="ECMAScript" stopProcessing="true">
<match url="iisnode.+" negate="true" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="Rewrite" url="server.js" />
</rule>
</rules>
</rewrite>
</system.webServer>
<!-- Remote debugging (Azure Website with git deploy): uncomment system.web below -->
<!--<system.web>
<httpRuntime targetFramework="4.5"/>
<customErrors mode="Off"/>
</system.web>-->
</configuration>

I tested your web.config file in my test node.js application, everything worked fine on my side. It should be any other reason which caused your issue. Could you kindly provide more info about your application, e.g. how you deploy to Azure Web Apps, what's your structure and any key code snippet related to the post functionality. These may help communities to detect the queston.
Meanwhile, you can try to leverage Log Stream tool to trace the all the info and stdout of your application while the Azure App is running.
You can login on your Azure Portal, navigate to Azure Apps blade, click Diagnostics Logs => Enable Application Logging (Filesystem), and then click Log stream to open the tool.

Related

How to deploy express-gateway on azure using app service

Created express-gateway application and now I am trying to deploy on azure and for that created Azure App Service, once app service created than use of Github deployment process, deployed code on app service and now when I trying to access app service on browser than I am getting 500.1001 error and on log message is like that iisnode was unable to establish named pipe connection to the node.exe process
Web.config
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your Node.js application, please visit
http://go.microsoft.com/fwlink/?LinkId=290972
-->
<configuration>
<appSettings>
<!--
<add key="StorageAccountName" value="" />
<add key="StorageAccountKey" value="" />
<add key="ServiceBusNamespace" value="" />
<add key="ServiceBusIssuerName" value="" />
<add key="ServiceBusIssuerSecretKey" value="" />
-->
</appSettings>
<system.webServer>
<!-- mimeMap enables IIS to serve particular file types as specified by fileExtension. -->
<staticContent>
<mimeMap fileExtension=".svg" mimeType="image/svg+xml" />
</staticContent>
<modules runAllManagedModulesForAllRequests="false" />
<!-- Web.Debug.config adds attributes to this to enable remote debugging when publishing in Debug configuration. -->
<iisnode watchedFiles="web.config;*.js;routes\*.js;views\*.pug"/>
<!-- Remote debugging (Azure Website with git deploy): Comment out iisnode above, and uncomment iisnode below. -->
<!--<iisnode watchedFiles="web.config;*.js;routes\*.js;views\*.pug"
loggingEnabled="true"
devErrorsEnabled="true"
nodeProcessCommandLine="node.exe --debug"/>-->
<!-- indicates that the server.js file is a Node.js application
to be handled by the iisnode module -->
<handlers>
<add name="iisnode" path="server.js" verb="*" modules="iisnode" />
<!-- Remote debugging (Azure Website with git deploy): Uncomment NtvsDebugProxy handler below.
Additionally copy Microsoft.NodejsTools.WebRole to 'bin' from the Remote Debug Proxy folder.-->
<!--<add name="NtvsDebugProxy" path="ntvs-debug-proxy/f45f6d32-816b-47f0-8bfa-47f7930108a4" verb="*" resourceType="Unspecified"
type="Microsoft.NodejsTools.Debugger.WebSocketProxy, Microsoft.NodejsTools.WebRole"/>-->
</handlers>
<security>
<requestFiltering>
<hiddenSegments>
<remove segment="bin" />
</hiddenSegments>
</requestFiltering>
</security>
<rewrite>
<rules>
<clear />
<!-- Remote debugging (Azure Website with git deploy): Uncomment the NtvsDebugProxy rule below. -->
<!--<rule name="NtvsDebugProxy" enabled="true" stopProcessing="true">
<match url="^ntvs-debug-proxy/.*"/>
</rule>-->
<!-- Don't interfere with requests for node-inspector debugging -->
<rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">
<match url="^server.js\/debug[\/]?" />
</rule>
<rule name="app" enabled="true" patternSyntax="ECMAScript" stopProcessing="true">
<match url="iisnode.+" negate="true" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="Rewrite" url="server.js" />
</rule>
</rules>
</rewrite>
</system.webServer>
<!-- Remote debugging (Azure Website with git deploy): uncomment system.web below -->
<!--<system.web>
<httpRuntime targetFramework="4.5"/>
<customErrors mode="Off"/>
</system.web>-->
</configuration>
Server.js
require('dotenv').config();
var request = require('request');
const path = require('path');
const gateway = require('express-gateway');
gateway()
.load(path.join(__dirname, 'config'))
.run();
gateway.config.yml
http:
port: 8080
admin:
port: 9876
host: localhost
apiEndpoints:
api:
host: localhost
paths: '/ip'
serviceEndpoints:
httpbin:
url: 'https://httpbin.org'
policies:
- basic-auth
- cors
- expression
- key-auth
- log
- oauth2
- proxy
- rate-limit
pipelines:
default:
apiEndpoints:
- api
policies:
# Uncomment `key-auth:` when instructed to in the Getting Started guide.
# - key-auth:
- proxy:
- action:
serviceEndpoint: httpbin
changeOrigin: true

Nothing happens when using method history.replaceState

I use azure app services for my nuxt application but when i use history.replaceState it doesnt replace the url. Running it on production on my own pc works fine but when I deploy it to azure it seems like its not doing anything. Maybe I did something wrong in my web.config?
(I also tried using this.$router.replace() which has the same results.)
selectBrand (brand) {
const errors = JSON.parse(JSON.stringify(this.error))
history.replaceState({}, null, window.origin + '/error/'+brand);
this.selectedBrand = brand
this.errorList = this.error.filter(name => name.cBrandname.includes(brand))
}
Here is my web.config
<?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>
<!-- Visit https://azure.microsoft.com/en-us/blog/introduction-to-websockets-on-windows-azure-web-sites/ for more information on WebSocket support -->
<webSocket enabled="false" />
<handlers>
<!-- Indicates that the server.js file is a node.js site to be handled by the iisnode module -->
<add name="iisnode" path="server" verb="*" modules="iisnode"/>
</handlers>
<rewrite>
<rules>
<!-- Do not interfere with requests for node-inspector debugging -->
<rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">
<match url="^server\/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 site entry point -->
<rule name="DynamicContent">
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True"/>
</conditions>
<action type="Rewrite" url="server"/>
</rule>
</rules>
</rewrite>
<!-- 'bin' directory has no special meaning in node.js and apps can be placed in it -->
<security>
<requestFiltering>
<hiddenSegments>
<remove segment="bin"/>
</hiddenSegments>
</requestFiltering>
</security>
<!-- Make sure error responses are left untouched -->
<httpErrors existingResponse="PassThrough" />
<!--
You can control how Node is hosted within IIS using the following options:
* watchedFiles: semi-colon separated list of files that will be watched for changes to restart the server
* node_env: will be propagated to node as NODE_ENV environment variable
* debuggingEnabled - controls whether the built-in debugger is enabled
See https://github.com/tjanczuk/iisnode/blob/master/src/samples/configuration/web.config for a full list of options
-->
<!--<iisnode watchedFiles="web.config;*.js"/>-->
</system.webServer>
</configuration>
Thanks for raising the question and contributing to Stack Overflow.
Reiterating the answer from what Jason has mentioned as this should be solution for the problem you're facing .
Just create a sample Nuxt App and try to publish it again and see if it helps.

iisnode: Publish an application inside an existing one

I'm trying to run two node applications, one inside another in IIS to have the proper rote:
http://server/node1
http://server/node1/node2
I have this scenario in my IIS:
Default Web Site
- node1
- node2
The struggle is that the first application node (node1) works fine, but the second keep giving me Status Code 500, however when I deploy it outsite the virtual directory (node1) works, like this:
Default Web Site
- node1
- node2
This is the web.config that I'm using:
<configuration>
<appSettings>
<!-- for node1 -->
<add key="DEPLOY_PATH" value="/node1" />
<!-- for node2 -->
<add key="DEPLOY_PATH" value="/node1/node2" />
</appSettings>
<system.web>
<customErrors mode="Off" />
</system.web>
<system.webServer>
<httpErrors existingResponse="PassThrough" />
<handlers>
<add name="iisnode" path="app.js" verb="*" modules="iisnode" />
</handlers>
<rewrite>
<rules>
<rule name="rewrite">
<match url="/*" />
<action type="Rewrite" url="app.js" />
</rule>
</rules>
</rewrite>
<iisnode maxNamedPipeConnectionRetry="1000" namedPipeConnectionRetryDelay="25000" />
<security>
<requestFiltering>
<hiddenSegments>
<add segment="node_modules" />
</hiddenSegments>
</requestFiltering>
</security>
</system.webServer>
</configuration>
I couldn't find anything on the web about it, or similar work. I want to know why the node2 application doesn't work when deployed inside node1.

Azure app breaks when updating Node version

I have upgraded the Node.js version to 8.8.1, and updated this in the process environmental variables, iisnode.yml, Web.config and package.json.
Nonetheless, requests going to the app now get rejected with the following error:
The iisnode module is unable to start the node.exe process. Make sure
the node.exe executable is available at the location specified in the
https://github.com/tjanczuk/iisnode/blob/master/src/samples/configuration/web.config>system.webServer/iisnode/#nodeProcessCommandLine
element of web.config. By default node.exe is expected in one of the
directories listed in the PATH environment variable.
I tried to update the file path in Kudu to reflect the path to the node.exe I'm interested in ("D:\Program Files (x86)\nodejs\8.1.1\node.exe"), but got an error saying I was not authorized to do this.
The relevant files:
iisnode.yml:
nodeProcessCommandLine: "D:\Program Files (x86)\nodejs\8.1.1\node.exe"
loggingEnabled: true
devErrorsEnabled: true
Web.config
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your Node.js application, please visit
-->
<configuration>
<appSettings>
<!--
<add key="StorageAccountName" value="" />
<add key="StorageAccountKey" value="" />
<add key="ServiceBusNamespace" value="" />
<add key="ServiceBusIssuerName" value="" />
<add key="ServiceBusIssuerSecretKey" value="" />
-->
</appSettings>
<system.webServer>
<!-- mimeMap enables IIS to serve particular file types as specified by fileExtension. -->
<staticContent>
<mimeMap fileExtension=".svg" mimeType="image/svg+xml" />
</staticContent>
<modules runAllManagedModulesForAllRequests="false" />
<!-- Web.Debug.config adds attributes to this to enable remote debugging when publishing in Debug configuration. -->
<!--<iisnode watchedFiles="web.config;*.js;routes\*.js;views\*.pug"/>-->
<!-- Remote debugging (Azure Website with git deploy): Comment out iisnode above, and uncomment iisnode below. -->
<iisnode watchedFiles="web.config;*.js;routes\*.js;views\*.pug"
loggingEnabled="true"
devErrorsEnabled="true"
nodeProcessCommandLine="D:\Program Files (x86)\nodejs\8.8.1\node.exe --debug"/>
<!-- indicates that the server.js file is a Node.js application
to be handled by the iisnode module -->
<handlers>
<add name="iisnode" path="index.js" verb="*" modules="iisnode" />
<!-- Remote debugging (Azure Website with git deploy): Uncomment NtvsDebugProxy handler below.
Additionally copy Microsoft.NodejsTools.WebRole to 'bin' from the Remote Debug Proxy folder.-->
<add name="NtvsDebugProxy" path="ntvs-debug-proxy/blablabla" verb="*" resourceType="Unspecified"
type="Microsoft.NodejsTools.Debugger.WebSocketProxy, Microsoft.NodejsTools.WebRole"/>
</handlers>
<security>
<requestFiltering>
<hiddenSegments>
<remove segment="bin" />
</hiddenSegments>
</requestFiltering>
</security>
<rewrite>
<rules>
<clear />
<!-- Remote debugging (Azure Website with git deploy): Uncomment the NtvsDebugProxy rule below. -->
<rule name="NtvsDebugProxy" enabled="true" stopProcessing="true">
<match url="^ntvs-debug-proxy/.*"/>
</rule>
<!-- Don't interfere with requests for node-inspector debugging -->
<rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">
<match url="^server.js\/debug[\/]?" />
</rule>
<rule name="app" enabled="true" patternSyntax="ECMAScript" stopProcessing="true">
<match url="iisnode.+" negate="true" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="Rewrite" url="index.js" />
</rule>
</rules>
</rewrite>
</system.webServer>
<!-- Remote debugging (Azure Website with git deploy): uncomment system.web below -->
<system.web>
<httpRuntime targetFramework="4.5"/>
<customErrors mode="Off"/>
</system.web>
</configuration>
In iisnode.yml, you have nodeProcessCommandLine pointing to 8.1.1 instead of 8.8.1. Maybe that's just it?

clustering node on iisnode using nodeProcessCountPerApplication

I have a web app in Azure which is using node.js and socket.io, and I decided to use the clustering supported by IISNODE, using nodeProcessCountPerApplication as below in my web.config
<iisnode nodeProcessCountPerApplication="0" />
However, when I apply this, I got 500.1013 internal server error, which states:
Most likely causes:
IIS received the request; however, an internal error occurred during the processing of the request. The root cause of this error depends on which module handles the request and what was happening in the worker process when this error occurred.
IIS was not able to access the web.config file for the Web site or application. This can occur if the NTFS permissions are set incorrectly.
IIS was not able to process configuration for the Web site or application.
The authenticated user does not have permission to use this DLL.
The request is mapped to a managed handler but the .NET Extensibility Feature is not installed.
I looked for examples but couldn't find anything similar. I am wondering what I am doing wrong here. I want to be able to use all processors of my machine.
Thanks !
I was able to use all processors of my App Service plan by using the following web.config file.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.webServer>
<webSocket enabled="false" />
<handlers>
<add name="iisnode" path="app.js" verb="*" modules="iisnode" />
</handlers>
<rewrite>
<rules>
<rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">
<match url="^app.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="app.js" />
</rule>
</rules>
</rewrite>
<security>
<requestFiltering>
<hiddenSegments>
<remove segment="bin" />
</hiddenSegments>
</requestFiltering>
</security>
<httpErrors existingResponse="PassThrough" />
<iisnode watchedFiles="web.config;*.js" devErrorsEnabled="true" nodeProcessCountPerApplication="0" />
</system.webServer>
</configuration>
As you are using socket.io on Azure Web App, you'll also need to set Web sockets to On in the Azure portal. See Using socket.io-redis on azure web service.

Resources