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
We'd love to have you contribute to Code Corps directly!
To do so, please read the guidelines in our CONTRIBUTING.md
.
We need to install the Ruby on Rails framework, the PostgreSQL database, and the Redis data store.
- Install Rails.
- Install and configure PostgreSQL 9.3+.
- Run
postgres -V
to see if you already have it. - Make sure that the server's messages language is English; this is required by the ActiveRecord Postgres adapter.
- 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 withPONG
- Install ElasticSearch
- On Mac, run
brew install elasticsearch
- Or for Linux or Windows, consult the setup guide
- On Mac, run
You'll want to clone this repository with git clone https://github.com/code-corps/code-corps-api.git
.
- Run
bin/setup
to set up and seed the database. - 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
- Stop your existing
redis-server
process - Run the api with
foreman start -f Procfile.dev
. This will start any service listed in that Procfile.
- You already have
redis-server
running. In the future, you'll need to run it, as well. - Start Sidekiq with
bundle exec sidekiq
- Start the Rails server with
rails s
Point your browser (or make a direct request) to http://api.lvh.me:3000/ping. There should be a {"ping":"pong"}
response from it.
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
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
- 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.