Skip to content

rigelstpierre/code-corps-api

 
 

Repository files navigation

Code Corps Rails API

Code Corps Rails Logo

Circle CI Dependency Status Code Climate Test Coverage Inline docs Slack Status

The Code Corps API is an open source Rails::API backend that powers the Code Corps platform. It includes:

  • developer and project matchmaking
  • project management tooling
  • a donations engine that distributes donations to projects

Contributing

We'd love to have you contribute to Code Corps directly!

To do so, please read the guidelines in our CONTRIBUTING.md.

Developer installation guide

Install Rails, PostgreSQL, Redis, and ElasticSearch

We need to install the Ruby on Rails framework, the PostgreSQL database, and the Redis data store.

  1. Install Rails.
  2. Install and configure PostgreSQL 9.3+.
  3. Run postgres -V to see if you already have it.
  4. Make sure that the server's messages language is English; this is required by the ActiveRecord Postgres adapter.
  5. Install and make sure you can run redis:
    • Follow the official quickstart guide
    • It's best to install it as a service instead of running it manually
    • To make sure everything works and the service is running, execute redis-cli ping in the console. It should respond with PONG
  6. Install ElasticSearch
    • On Mac, run brew install elasticsearch
    • Or for Linux or Windows, consult the setup guide

Clone this git repository

You'll want to clone this repository with git clone https://github.com/code-corps/code-corps-api.git.

Set up the Rails app

  1. Run bin/setup to set up and seed the database.
  2. Try running the specs: bundle exec rake spec

From here, we need to start the web server, Redis, and Sidekiq processes. You can either:

Use foreman to run your application's processes

  1. Stop your existing redis-server process
  2. Run the api with foreman start -f Procfile.dev. This will start any service listed in that Procfile.

Alternatively, run your application's processes individually

  1. You already have redis-server running. In the future, you'll need to run it, as well.
  2. Start Sidekiq with bundle exec sidekiq
  3. Start the Rails server with rails s

To make sure the API is running properly

Point your browser (or make a direct request) to http://api.lvh.me:3000/ping. There should be a {"ping":"pong"} response from it.

Working with Ember

The CodeCorps API is intended to work alongside a client written in Ember. For that purpose, the rails application exposes all of it's API endpoints behind an api. subdomain.

On the Ember client side of things, we use ember-cli-deploy with a redis plugin to deploy the client application to redis. Multiple revisions are maintained this way.

Any server request pointing to the main domain and not the api. subdomain is redirected to ember_index_controller#index. There, depending on the remainder of the request path and the current environment, a specific revision of the ember app is retrieved from redis and rendered. This can be

  • the development revision, if the current environment is development
  • a specific deployed revision in production if the request contains a revision parameter in SHORT_UUID format
  • the latest deployed revision in production if the request does not contain a revision parameter
  • A plain text string containing "INDEX NOT FOUND" if a revision was specified, but the key for the specified revision was not found by redis

Debugging the API

Because the app is running foreman, debugging use pry won't work the same way. If you want to use pry, you'll need to debug remotely.

Add binding.remote_pry where you want to pause:

class UsersController < ApplicationController
  def index
    binding.remote_pry
    ...
  end
end

Load a page that triggers the code. Connect to the session:

$ bundle exec pry-remote

Built with

  • Rails::API — Our backend API is a Rails::API app which uses JSON API to respond RESTfully to requests.
  • Ember.js — Our frontend is an Ember.js app that communicates with the Rails API.
  • PostgreSQL — Our primary data store uses Postgres.

About

Rails API for Code Corps.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Ruby 99.0%
  • Other 1.0%