Path to use in web.config when deploying Meteorjs - azure

Trying to deploy a meteorjs app to Azure, everything looks configured correctly except I'm not sure what to point to:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation batch="false" />
</system.web>
<system.webServer>
<handlers>
<add name="iisnode" path="server.js" verb="*" modules="iisnode" />
</handlers>
<rewrite>
<rules>
<rule name="myapp">
<match url="/*" />
<action type="Rewrite" url="server.js" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
I do not have a server.js. I am deploying this from nitrous.io, where the app works as expected. Do I need to add a server.js file, and if so, what should be the content? Otherwise, what file is appropriate to point to?

Builded Meteor Application on output has main.js in root folder of your application, you should point your web server onto this file.
In rewrite rule use regular expression:
<match url="^(.*)$" ignoreCase="false" />
So your config file will be:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation batch="false" />
</system.web>
<system.webServer>
<handlers>
<add name="iisnode" path="main.js" verb="*" modules="iisnode" />
</handlers>
<rewrite>
<rules>
<rule name="myapp">
<match url="^(.*)$" ignoreCase="false" />
<action type="Rewrite" url="main.js" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Also do not forget to set ENV variables for builded Meteor: MONGO_URL, ROOT_URL (domain with protocol, like: http://my.site), MAIL_URL, etc.

Related

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.

Internal server error of node js app after deployment to azure

I have created a sample bot,which is working in bot emulator and azure bot service with localhost url,but when i deployed to azure and hit its live url it is giving internal error
The page cannot be displayed because an internal server error has occurred.
and web config file is
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="iisnode" path="app.js" verb="*" modules="iisnode"/>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Headers" value="Content-Type" />
<add name="Access-Control-Allow-Methods" value="GET,POST,PUT,DELETE,OPTIONS" />
<add name="Access-Control-Allow-Credentials" value="true" />
</handlers>
<rewrite>
<rules>
<rule name="DynamicContent">
<match url="/*" />
<action type="Rewrite" url="app.js"/>
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
live url of site
https://hotel-reserve.azurewebsites.net/api/messages

Running Keystone.js with IISnode

I'm fairly new to both Keystone and IISnode so bear with me. I've succesfully been able to run express projects with IISnode and I can run keystone.js projects with node but merging the two has been difficult. When I run the ETW traces alongside I get a "iisnode scheduled a retry of a named pipe connection to the node.exe process" multiple times before I shut it down. I've tried hooking iisnode directly to the keystone index.js file (see below from the web.config) and also to the keystone.js file at the root of the project.
<handlers>
<add name="iisnode" path="node_modules/keystone/index.js" verb="*" modules="iisnode" />
</handlers>
My hunch is that I need to hook it up to the keystone.js file as you normally do to start up the project but you typically need to add a 'keystone' parameter alongside which I'm not quite sure how I can do this with iisnode. Can anyone help me out?
The web.config handler path should be set to your application's entry point, and not node_modules\keystone\index.js. If you used the keystone Yoeman generator, the entry point is the keystone.js file in the root folder of your app.
<configuration>
<system.webServer>
<handlers>
<add name="iisnode" path="keystone.js" verb="*" modules="iisnode" />
</handlers>
...
</system.webServer>
</configuration>
I have more detail instruction of how to setup keystone.js at IIS.
http://www.dakehe.info/blog/post/deploy-keystonejs-node-cms-at-iis
<configuration>
<system.webServer>
<handlers>
<add name="iisnode" path="keystone.js" verb="*" modules="iisnode" />
</handlers>
<defaultDocument enabled="true">
<files>
<add value="keystone.js" />
</files>
</defaultDocument>
<rewrite>
<rules>
<rule name="Catch All">
<match url="/*" />
<conditions>
<add input="{PATH_INFO}" pattern=".+\.js\/debug\/?" negate="true" />
</conditions>
<action type="Rewrite" url="keystone.js" />
</rule>
</rules>
</rewrite>
<directoryBrowse enabled="false" />
<iisnode node_env="production" loggingEnabled="true" debuggingEnabled="true" devErrorsEnabled="true" />
</system.webServer>
</configuration>

IIS returns 500 when Node app returns a 4xx

I have also asked this on the iisnode github project
I am using IISNode via a Windows Azure Website.
If my Node app returns a 2xx status code (200, 201, etc), then all is well and works as expected.
if my Node app returns a 4xx status code, for example:
response.send(404, "not found") (I am using Restify) then I get a 500 sent to the client and the body is simply "The page cannot be displayed because an internal server error has occurred."
If I do azure site log tail <sitename>, then when the 500 gets sent to the client, the log contains HTML of a 404.
...
<body>
<div id="content">
<div class="content-container">
<h3>HTTP Error 404.0 - Not Found</h3>
<h4>The resource you are looking for has been removed, had its name changed,
or is temporarily unavailable.</h4>
</div>
...
I really just want IISNode/IIS to take my 404 and send it on down to the client. This is also true of 401s, 409s, etc. They all cause a 500 to get sent instead.
I have tried <customErrors mode="off" /> and <httpErrors existingResponse="passThrough" /> in my web.config to no avail. Here is my web.config now:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.web>
<customErrors mode="off" />
</system.web>
<system.webServer>
<httpErrors existingResponse="PassThrough" />
<staticContent>
<mimeMap fileExtension=".svg" mimeType="image/svg+xml" />
<mimeMap fileExtension=".ico" mimeType="image/x-icon" />
</staticContent>
<handlers>
<add name="iisnode" path="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.js"/>
<match url="/*" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
For what it's worth, I can't get IISnode to do anything but return 200s from my node app. Trying to get IIS to serve my static files, enable node-inspector, or really any of the more interesting IISNode features cause a 500 for me. No idea why, and would love to get past it!
Similar StackOverflow Questions
this question is pretty much exactly my problem. Except that <httpErrors existingResponse="PassThrough" /> does not work for me. I feel like I have something more fundamentally wrong with my IISNode setup, so if anyone has any ideas on things to try I'm all ears.
for some reason the following section in your config is causing this issue:
<staticContent>
<mimeMap fileExtension=".svg" mimeType="image/svg+xml" />
<mimeMap fileExtension=".ico" mimeType="image/x-icon" />
</staticContent>
As a workaround, remove this section if possible and retry. I will investigate why this section is causing this issue.
As Ranjith pointed out, the staticContent section is the cause of the conflict. I just found you can limit those entries inside of location entries, so you can get all of IISNode as desired and still serve up static content. My web.config now looks like this:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.web>
<customErrors mode="off" />
</system.web>
<system.webServer>
<handlers>
<add name="iisnode" path="server.js" verb="*" modules="iisnode"/>
</handlers>
<rewrite>
<rules>
<rule name="Redirect to https" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Found" appendQueryString="true" />
</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>
<httpErrors existingResponse="PassThrough" />
</system.webServer>
<location path="public/fonts">
<system.webServer>
<staticContent>
<mimeMap fileExtension=".woff" mimeType="application/font-woff" />
</staticContent>
</system.webServer>
</location>
</configuration>
The added location entry at the end works around the 500 and static content conflicts.
I'm getting the exact same...500 error page returned from Azure/IIS. I used the web.config that Azure automatically generated as the basis, then added <customErrors mode="off" /> and <httpErrors existingResponse="PassThrough" />. I also removed the default staticContent node. Nothing is working.
Below is the web.config that I'm uploading to Azure. What in here is causing IIS/iisnode to return a 500 error page instead of the simple text error message I have node/express returning to the client?
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.web>
<customErrors mode="off" />
</system.web>
<system.webServer>
<httpErrors existingResponse="PassThrough" />
<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="DynamicContent">
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True"/>
</conditions>
<action type="Rewrite" url="server.js"/>
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
This works for me:
<?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="DynamicContent">
<match url="/*" />
<action type="Rewrite" url="app.js"/>
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
I had the same issue (IIS Node on Win Server 2012R2). So I did not get the target content in the body.
At the beginning I had response:
code: 400
body: Bad Request
Then I added <httpErrors existingResponse="PassThrough" /> and I got response:
code: 500
body: The page cannot be displayed because an internal server error has occurred
Then I have changed IIS Feature Delegation for "Error Pages" to "Read/Write" and this resolved my issue. Finally I had proper response:
code: 400
body: { "error": {...} }
I hope this helps.

Set Node.js Environment Variable (NODE_ENV) in iisnode to Production/Development/Test

How do we tell iisnode to run our Node.js application environment in production/development/test?
We have successfully gotten our Node.js app running with iisnode but process.env.NODE_ENV is coming out as 'undefined'.
At the moment, our web.config file is written this way:
<configuration>
<system.webServer>
<handlers>
<add name="iisnode" path="app.js" verb="*" modules="iisnode" />
</handlers>
<rewrite>
<rules>
<rule name="app">
<match url="/*" />
<action type="Rewrite" url="app.js" />
</rule>
</rules>
</rewrite>
<security>
<requestFiltering>
<hiddenSegments>
<add segment="node_modules" />
</hiddenSegments>
</requestFiltering>
</security>
</system.webServer>
<appSettings>
<add key="NODE_ENV" value="production" />
</appSettings>
</configuration>
Joachim is right above that adding <iisnode node_env="production" /> to web.config allows control over the NODE_ENV value. Another way is to add the iisnode.yml file next to your web.config, and in there spcify the NODE_ENV value as node_env: production. See other settings you can use in iisnode.yml at https://github.com/tjanczuk/iisnode/blob/master/src/samples/configuration/iisnode.yml
For the sake of clarity the web.config file would look like this:
<configuration>
<system.webServer>
<handlers>
<add name="iisnode" path="app.js" verb="*" modules="iisnode" />
</handlers>
<rewrite>
<rules>
<rule name="app">
<match url="/*" />
<action type="Rewrite" url="app.js" />
</rule>
</rules>
</rewrite>
<security>
<requestFiltering>
<hiddenSegments>
<add segment="node_modules" />
</hiddenSegments>
</requestFiltering>
</security>
<iisnode NODE_ENV="production" /> <=== Add env required here
</system.webServer>
</configuration>

Resources