At last I have got this going.
For the benefit of others, this is what I did -
To understand it you must replace zzzzzzzzzzzz with your website url (this forum won't let me repeat url's)
I wanted it all to work below a subfolder of my site, so set up an iis site zzzzzzzzzzzz/xred
First just try 'hello world' in a .htm file to make sure iis is serving something at zzzzzzzzzzzz/xred/hello.htm
Then copy in hello.js and its web.config file from the iisnode examples and try zzzzzzzzzzzz/xred/hello.js to check iis + iisnode + node are all playing correctly together.
Now the hard part, to get node-red to work - this comes from an idea sparked by @TotallyInformation and the source of the azure implementation node-red-azure-webapp on github, and a lot of looking at its result in an azure site I created with it.
- The stock install as per nodered.org/docs/platforms/windows is no good to you; Install node-red again NOT as a global module, in, or close to your new website. I installed it in my /xred folder, so in a CMD box, something like:
cd C:\mywebsites\mysite\xred
npm install node-red
This creates a \xred\node_modules\ folder with all the node-red stuff in it.
-
I also created a folder tree at C:\mywebsites\nodered\.node-red\ for my userDir but this may not be necessary if it makes it itself on first run, but I wasn't sure (see settings.js below.)
-
\xred\server.js This is a sort of wrapper for node-red to run in
var express = require("express");
var RED=require('node-red');
var app= express();
var http=require('http');
const PORT=process.env.PORT; //||8000;
var server=http.createServer(app);
var settings=require("./settings.js");
RED.init(server,settings);
app.use(settings.httpAdminRoot,RED.httpAdmin);
app.use(settings.httpNodeRoot,RED.httpNode);
server.listen(settings.uiPort);
console.log(`listening port:${settings.uiPort}`);
RED.start();
-
\xred\settings.js (only important settings shown, everything else to your taste)
module.exports = {
httpAdminRoot:"/xred/",
httpNodeRoot: "/xred/",
userDir:"../../nodered/.node-red/",
uiPort: process.env.PORT, // || 8000
}
These 2 Root paths caused me a lot of hair pulling, if they're not exactly right then according to the logs node-red runs but all you get on screen is
cannot GET
which is something to do with express being finicky about paths.
-
\xred\web.config More or less iisnode stock.
<!--
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>
<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.js" verb="*" modules="iisnode" />
<!--<add name="iisnode" path="hello.js" 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.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{PATH_INFO}" />
</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.js" />
</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:
See iisnode on github for a full list of options
-->
<iisnode watchedFiles="web.config;*.js" loggingEnabled="true" logDirectory="iisnode" debuggingEnabled="true" />
</system.webServer>
</configuration>
- Now you should be able to navigate to www.mysite.com/xred and node-red will start.
If it says
Not started
I think this means it is re-starting after having detected a change in one of your iisnode watchedFiles , so just wait a bit and refresh the page - bob should be your uncle
I didn't get the special iisnode debug feature working as in zzzzzzzzzzzzzzzz/xred/hello.js/debug but it didn't work for me in the stock iisnode examples either - you just get a lot of uncaught syntax errors.
Protect your mode-red server with a password at least
iisnode exposes a folder zzzzzzzzzzzzzz/xred/iisnode/ with useful debug info but obviously rather insecure. The recommendation is to change this folder name in iisnode settings to something very cryptic like a uuid
Richard