codeforamerica / trailsyserver

API and admin UI server for Trailsy data
7 stars 15 forks source link

TrailsyServer

Trailsyserver is one of the components, along with Trailsy, of To The Trails, a web application for storing and displaying hiking/biking/equestrian trail data.

To The Trails was developed by 2013 Code for America Fellows working with park and trail organizations in Summit County, Ohio. The application is lightly customized for use in Summit County, but could be repurposed with minimal effort.

The Trailsyserver component includes:

Special Note: The Trailsy repository is currently a submodule of this Trailsyserver repository, so if you clone this repository, you can use git submodule init then git submodule update to create a copy of Trailsy in the 'public' directory of Trailsyserver. This setup reduces from two to one the number of Heroku app instances required to run a full instance of To The Trails.

Requirements

The Trailsy repo is included in this app's "/public" directory as a git submodule. This allows for a single Heroku instance to run both the front-end and back-end code, while keeping the repositories separate. In development, it's recommended to check out the repositories separately, as updating submodule code can be challenging.

Sample working resource requests

Setup notes

Heroku setup

(For quick step-by-step instructions for creating a new deploy of To The Trails/Trailsy, try the new deploy instructions on the Trailsy repository wiki.)

To set up an instance on Heroku, you need a instance of PostGIS available. The production To The Trails application uses Heroku's PostGIS service.

An Amazon Web Services account is also required for photo storage in Amazon S3. The application uses Paperclip to manage photo attachments, so it could be converted to use any other Paperclip-supported storage backend.

To install on Heroku, you'll need to set the following app config vars:

To add these to your Heroku app (Heroku Toolbelt required):

heroku config:add BUILDPACK_URL=https://github.com/ddollar/heroku-buildpack-multi.git
heroku config:add GDAL_BINDIR=/app/vendor/gdal/1.10.0/bin
heroku config:add DATABASE_URL=[your database URL]
heroku config:add TRAILSY_AWS_BUCKET=[bucket] 
heroku config:add TRAILSY_AWS_ACCESS_KEY_ID=[id] 
heroky config:add TRAILSY_AWS_ACCESS_SECRET_ACCESS_KEY=[key]

To initialize the database and set up the initial users:

heroku run rake db:create && db:migrate && db:seed

To populate the database with sample trails, trailheads, and segments from Cuyahoga Valley National Park and Metro Parks, Serving Summit County:

heroku run rake load:all

Local setup

You need the GDAL/OGR package installed locally.

Database environment variables required

There are two "development" Rails environments available:

Other environment variables required

Path to GDAL binaries (for ogr2ogr)

Users to create during rake db:seed

Three users will be set up on DB creation. They should be email addresses.

The first is the admin user. This user can approve new user accounts:

These users will have organization field values of "NPS" and "MPSSC" respectively (more generic user names and organizations should be provide for testing, but for now they're not):

All of these initial users will share the single password in the following environment variable:

Then run

rake db:create && db:migrate && db:seed

to initialize the database, and optionally run

rake load:all

to load sample data from Cuyahoga Valley National Park and Metro Parks, Serving Summit County.

To start Trailsyserver, start it with rails server. If you're planning on using it with the Trailsy front-end, change API_HOST in the first lines of trailhead.js to point to your instance of Trailsyserver.