Git Product home page Git Product logo

restify-postgis's Introduction

Test Map of PostGIS data

powered by RESTify, PostGIS, and Leaflet maps

A basic instant mapping demo using PostGIS, node-restify, LeafLet Maps and map tiles from Stamen, to visualize data from a postgres database. Based on Ryan Jarvinien's restify-postgis repo (https://github.com/ryanj/restify-postGIS) and the related post on OpenShift.com: https://www.openshift.com/blogs/instant-mapping-applications-with-postgis-and-nodejs

Basic Configuration

This app uses the config npm module, which loads it's configuration details from the config/defaults.json file. This configuration takes advantage of several environment variables whenever they are available. On OpenShift, many of these values are automatically provided for your application by their associated cartridge add-on service:

module.exports = {
  port: process.env.PORT || process.env.OPENSHIFT_NODEJS_PORT || 3000,
  ip: process.env.OPENSHIFT_NODEJS_IP || '127.0.0.1',
  pg_config: process.env.OPENSHIFT_POSTGRESQL_DB_URL || 'postgresql://127.0.0.1:5432',
  table_name: process.env.OPENSHIFT_APP_NAME || 'parks'
}

Sensible defaults allow us to run the same code in multiple environments.

If you plan on using the port-forwarded DB connection from the previous step in your local development stage, then you will need to supply some additional DB authentication credentials to your application via the OPENSHIFT_POSTGRESQL_DB_URL environment variable.

Environment Variables

Now, set your OPENSHIFT_POSTGRESQL_DB_URL environment variable, substituting your own DB_USERNAME, DB_PASSWORD, LOCAL_DB_IP, and LOCAL_DB_PORT:

export OPENSHIFT_POSTGRESQL_DB_URL="postgres://DB_USERNAME:DB_PASSWORD@LOCAL_DB_IP:LOCAL_DB_PORT"

My application's command ended up looking like this:

export OPENSHIFT_POSTGRESQL_DB_URL="postgres://admin32jk510:[email protected]:5433"

This app also expects to use a Postgres table_name that matches your application's name (as defined within OpenShift). When running this application on OpenShift, the OPENSHIFT_APP_NAME environment variable will be automatically populated. If you didn't name your application "parks" (the default value for this option), then you will likely need to set an extra environment variable containing your table name in your local dev environment:

export OPENSHIFT_APP_NAME=parks

Testing your connection

You can verify that your port-forwarding tunnel is active, and that your environment variables are configured correctly by using them to make a DB connection using the psql command-line client:

psql $OPENSHIFT_POSTGRESQL_DB_URL/$OPENSHIFT_APP_NAME

This should provide a direct connection to your OpenShift-hosted database instance.

Here you can verify that your application's automatic database import procedures have successfully completed, by checking the number of records in our DB table:

select count(*) from parks;

The result should be 547. As usual, if you named your application something other than parks, you'll need to modify above the command to match your particular configuration.

Starting your Local Webserver

With your dependencies installed, your port-forwarding tunnel established, and your environment variables set, firing up a local server should be as simple as typing:

npm start

Your dev server should be available at the default address: localhost:3000

Deploying updates to OpenShift

When you're ready, you can push changes to your OpenShift-hosted application environment using the standard git workflow:

  1. Add your changes to a changeset:

    git add filename1 filename2

  2. Mark the changeset as a Commit:

    git commit -m 'describe your changes here'

  3. Push the Commit to OpenShift

    git push

License

This code is dedicated to the public domain to the maximum extent permitted by applicable law, pursuant to CC0 (http://creativecommons.org/publicdomain/zero/1.0/)

restify-postgis's People

Contributors

claytonrsh avatar ryanj avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.