Skip to content

Instantly share code, notes, and snippets.

@HCanber
Last active Apr 21, 2018
Embed
What would you like to do?
Host Sinopia in IIS on Windows
{
"name": "iisnode-sinopia",
"version": "1.0.0",
"description": "Hosts sinopia in iisnode",
"main": "start.js",
"dependencies": {
"sinopia": "^1.3.1"
}
}

These instructions were written for Windows Server 2012, IIS 8, Node.js 0.12.3, iisnode 0.2.16 and Sinopia 1.3.1

  1. Install IIS
  2. Install iisnode. Make sure you install prerequisites (Url Rewrite Module & node) as explained in the instructions for iisnode
  3. Create a new folder in Explorer where you want to host Sinopia. For example C:\Sinopia. Save package.json, start.js and web.config in this folder.
  4. Create a new site in Internet Information Services Manager. You can name it whatever you want. I'll call it Sinopia in these instructions. Specify the path to where you saved all files and a port number.
  5. Go back to Explorer and give the user that runs the application pool modify rights to the folder you just created. If you've named the new site Sinopia and did not change the app pool, it's running under an ApplicationPoolIdentity and you should give the user IIS AppPool\Sinopia modify rights see instructions if you need help. (You can restrict access later if you want so that it only has modify rights on the iisnode and sinopia\storage)
  6. Start a command prompt and execute the commands below to download Sinopia:
cd c:\Sinopia
npm install
  1. Make sure you have an inbound rule accepting TCP traffic to the port in Windows Firewall
  2. Thats it! Now you can navigate to the host and port that you specified

A default configuration file will be created c:\Sinopia\sinopia\config.yaml

You can see stdout logging if you go to the url /iisnode

process.argv.push('-l', 'unix:' + process.env.PORT);
require('./node_modules/sinopia/lib/cli.js');
<configuration>
<system.webServer>
<!-- indicates that the start.js file is a node.js application
to be handled by the iisnode module -->
<handlers>
<add name="iisnode" path="start.js" verb="*" modules="iisnode" />
</handlers>
<rewrite>
<rules>
<!-- iisnode folder is where iisnode stores it's logs. These should
never be rewritten -->
<rule name="iisnode" stopProcessing="true">
<match url="iisnode*"/>
<action type="None"/>
</rule>
<!-- Rewrite all other urls in order for sinopia to handle these -->
<rule name="sinopia">
<match url="/*" />
<action type="Rewrite" url="start.js" />
</rule>
</rules>
</rewrite>
<!-- exclude node_modules directory and subdirectories from serving
by IIS since these are implementation details of node.js applications -->
<security>
<requestFiltering>
<hiddenSegments>
<add segment="node_modules" />
</hiddenSegments>
</requestFiltering>
</security>
</system.webServer>
</configuration>
@arnarleifs
Copy link

arnarleifs commented Jun 20, 2017

I am having troubles with npm publish because of there seems to be some kind of a rewrite problems. Have you been able to publish successfully using the settings above?

@HCanber
Copy link
Author

HCanber commented Aug 22, 2017

@arnarleifs
Sorry for not responding sooner. This is the web-config we use for our instance of Sinopia. Note: We don't start with start.js but with index.js instead.

<configuration>
  <system.webServer>

    <httpErrors existingResponse="PassThrough" />
  
    <handlers>
      <!-- Handler for non Socket.io Apps -->
      <add name="iisnode" path="index.js" verb="*" modules="iisnode" />
      
      <!-- Handler for Socket.io Apps -->
      <!-- <add name="iisnode-socket.io" path="index.js" verb="*" modules="iisnode" /> -->
    </handlers>

    <rewrite>
      <!-- In order to be able to overwrite HTTP_X_ORIGINAL_URL we must allow them 
           Note: This might need an update to ApplicationHost.config. This file is located in %windir%\system32\inetsrv\config.
           Change
           <section name="allowedServerVariables" overrideModeDefault="Deny" />
           to
           <section name="allowedServerVariables" overrideModeDefault="Allow" />
           -->
      <allowedServerVariables>
        <add name="HTTP_X_ORIGINAL_URL" />
        <add name="UNENCODED_URL" />
      </allowedServerVariables>
      <rules>
        <!-- Don't interfere with requests for iisnode -->
        <rule name="LogFile" patternSyntax="ECMAScript" stopProcessing="true">  
          <match url="iisnode" />  
        </rule>
        <!-- Don't interfere with requests for node-inspector debugging -->
        <rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">
          <match url="^index.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{{REQUEST_URI}}"/>  
        </rule>
        -->
        <rule name="DynamicContent">  
          <conditions>  
            <add input="{{REQUEST_FILENAME}}" matchType="IsFile" negate="true" />  
          </conditions>  
          <action type="Rewrite" url="index.js" />
          <match url=".*" />
          <!-- Overwrite with the unencoded url. See https://github.com/tjanczuk/iisnode/issues/217#issuecomment-206953773
               We need this as long as https://github.com/tjanczuk/iisnode/pull/486 is not merged --> 
          <serverVariables>
            <set name="HTTP_X_ORIGINAL_URL" value="{UNENCODED_URL}" />
          </serverVariables>
        </rule>

        <!-- 
        <rule name="SocketIO" patternSyntax="ECMAScript">
          <match url="socket.io.+" />
          <action type="Rewrite" url="index.js"/>
        </rule>
        -->
      </rules>
    </rewrite>

  	<security>
      <requestFiltering>
        <hiddenSegments>
          <remove segment="bin" />

          <!--Hide the node_modules folder-->
         <add segment="node_modules" />
      	</hiddenSegments>
      </requestFiltering>
   	</security>

    <directoryBrowse enabled="false" />

    <iisnode node_env="production" enableXFF="true" promoteServerVars="AUTH_USER" nodeProcessCommandLine="" />

  </system.webServer>
</configuration>

@KEMBL
Copy link

KEMBL commented Aug 29, 2017

Guys, who has problems with addusers command try to add this to web.config:
<modules> <remove name="WebDAVModule"/> </modules> inside system.webServer tag

@mcaden
Copy link

mcaden commented Dec 1, 2017

In the updated web.config, this line:
<iisnode node_env="production" enableXFF="true" promoteServerVars="AUTH_USER" nodeProcessCommandLine="" />

Was giving me a 500.1000 internal server error. Removing the nodeProcessCommandLine attribute completely resolved the problem.

Additionally, after following this I realized that Sinopia hasn't had a commit in years. Verdaccio seems to be the evolution of it. For any that are interested, the only thing you really have to do differently based upon this thread is to update the 2nd line in your start.js/index.js file to use require('./node_modules/verdaccio/src/lib/cli.js'); instead of the sinopia one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment