2

I have built an API using Loopback. Now that it's time to host it on my Windows machine, Googling turned up two distinct options: 1) using NSSM to create a Service, or 2) using IISNode, a IIS module, to host the API using an IIS process. Since the benefits of using IIS seemed too strong to ignore, I chose that option.

The loopback documentation states that iisnode can be used to host a loopback api, but then fails to provide any guidance on the topic.

Iisnode documentation also has a few very basic examples, some based around Express (which loopback is built upon), but doesn't make it clear how to adapt a loopback application for use with iisnode. In all of their simplistic examples, the main node file is located at the root level of the node project. Loopback, however, keeps its at "~/server/server.js". This makes it unclear about where to place and configure the web.config file necessary for iisnode to work.

Is anyone aware of a decent tutorial or walk-though for hosting a Loopback project in IIS using iisnode? All I found are vague articles stating to the effect of "well...it should work." Has anyone successfully hosted a loopback project using iisnode?

2 Answers2

0

I'm not sure that you need a Loopback specific tutorial to help you out here. You just need to modify your Web.config.

Inside your Web.config there needs to be an iisnode handler. This instructs IISNode which file is the main file in your project. To direct traffic to your server file path simply change the path attribute on the handler.

<handlers>
  <add name="iisnode" path="/server/server.js" verb="*" modules="iisnode"/>
</handlers>

I've created a couple different walkthroughs for setting up an IISNode app with Express but they are applicable to really to anything being setup with IISNode.

Graham
  • 7,431
  • 18
  • 59
  • 84
peteb
  • 18,552
  • 9
  • 50
  • 62
  • 1
    Yes, the web.config file needs to point to the Loopback's main file. I have tried that, but sadly with no success. Maybe it's because of my site's setup in IIS? The site has a generic landing HTML page at the top level. In that site, I created a subdirectory, "Compass", under which I want host the Loopback API. It was in the "Compass" directory where the web.config file is located. Based on the examples I read, and that you referenced, the subdirectory seemed like the appropriate location. But no joy. I have verified that iisnode is an installed module. But, I'll try again tonite. – user3356792 Dec 01 '16 at 19:45
0

Make sure you follow this small check. Loopback hosting on web servers has a known issue(Not exactly an issue, but a protection feature, which can trip up first time deployer):

https://github.com/masonkmeyer/loopback-azure

The app.start() is called only when loopback's server.js is invoked directly. But webservers like IIS usually invoke the main script by requiring it. The solution suggested above is a little inelegant, in the sense that it does not guarantee that app.start will be called only after boot completes setting up rest endpoints.

Otherwise the web.config is pretty straight forward. The following helped me with the configuration a bit: https://tomasz.janczuk.org/2011/08/using-url-rewriting-with-nodejs.html

adgang
  • 71
  • 1
  • 3