Skip to content

Instantly share code, notes, and snippets.

@sirws
Last active August 29, 2015 14:20
Show Gist options
  • Save sirws/af77f664da000f295f6d to your computer and use it in GitHub Desktop.
Save sirws/af77f664da000f295f6d to your computer and use it in GitHub Desktop.
Installing Koop with IIS and iisnode

#Installing Koop on an IIS Server with iisnode

  1. Install latest version of node.js for windows (https://nodejs.org/)
  2. Install the URL Rewrite module for IIS (http://www.iis.net/downloads/microsoft/url-rewrite)
  3. Install iisnode from GitHub (https://github.com/tjanczuk/iisnode)
  run C:\Program Files\iisnode\setupsamples.bat from command prompt (run as Administrator/elevated privileges)
  test that it works (http://localhost/node/helloworld/hello.js)
  1. Install PostgreSQL 9.4.1 (http://www.enterprisedb.com/products-services-training/pgdownload#windows)

  2. Follow instructions to implement a persistent cache (https://github.com/koopjs/koop-sample-app/blob/master/docs/PG_CACHE.md)

  3. Install cURL for Windows (http://www.confusedbycode.com/curl/)

  4. Install koop-sample-app (https://github.com/koopjs/koop-sample-app)

  5. Add virtual directory to iis for koop and point to koop-sample-app location (in my case d:\koop-sample-app) Koop Virtual Dir

  6. Add web.config with URL rewrite mod to d:\koop-sample-app

    <configuration>
      <system.webServer>
    
        <!-- indicates that the hello.js file is a node.js application 
        to be handled by the iisnode module -->
    
        <handlers>
          <add name="iisnode" path="server.js" verb="*" modules="iisnode" />
        </handlers>
        
    	<rewrite>
    		<rules>
    		   <rule name="server">
    			 <match url="/*" />
                 <action type="Rewrite" url="server.js" />
               </rule>
    		</rules>
    	</rewrite>
    	
      </system.webServer>
    </configuration>
    
  7. Update server.js in koop-sample-app folder to: https://github.com/koopjs/koop-sample-app/blob/master/docs/PG_CACHE.md

  var express = require("express"),
  cors = require('cors'),
  config = require("config"),
  koop = require('koop')( config ),
  socrata = require('koop-socrata'),
  ckan = require('koop-ckan'),
  github = require('koop-github'),
  agol = require('koop-agol'),
  gist = require('koop-gist'),
  pgCache = require('koop-pgcache');
  koop.registerCache( pgCache );

and koopjs/koop-app-example#9

  http.createServer(app).listen(process.env.PORT || config.server.port);
  1. update koop-sample-app\config\default.json to use postgres (https://github.com/koopjs/koop-sample-app/blob/master/docs/PG_CACHE.md)
  {
      "server": {
          "port": 1337
      },
      "data_dir": "/usr/local/koop/",
      "db": {
        "conn": "postgres://username:password@localhost/koopdev"
      }
  }
  1. update d:\koop-sample-app\server.js to allow koop to run at a virtual dir (i.e. /koop)
  // add koop middleware
  //app.use( koop );
  app.use('/koop', koop ); //This is changed to all koop to run at a different location
  
  //app.get('/status', function(req, res){
  app.get('/koop/status', function(req, res){ //Have to listed for status at the right location
    res.json( koop.status );
  });
  
  // serve the index
  //app.get("/", function(req, res, next) {
  app.get("/koop", function(req, res, next) { //If user requests the /koop root, need to give them the right data
    res.send('Koop Sample App!');
  });
  1. Add your socrata site using cURL

    curl --data "host=https://data.wa.gov&id=wa" localhost/koop/socrata
    
  2. Verify your socrata provider is working by visiting: http://localhost/koop/socrata

  3. Test an actual dataset by visiting something like: http://50.18.49.187/koop/socrata/wa/3uf4-3kn2/FeatureServer

@jgravois
Copy link

can you add this to the koop wiki? that'd make it easier for others to help keep it up to date (for example, @ngoldman cleaned up the logic in server.js and revised the way we get custom ports)

it'd also probably be helpful to mention explicitly the need to run npm install (see here)

at some point we'll be aggregating doc like this for http://koopjs.github.io, but for now i think the koop wiki is a good collection location.

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