The API for pokedextracker.com. It's written in Node.js v5 using the following libraries/packages:
- Hapi - API Framework
- Joi - Data Validator
- Bookshelf - ORM
- Knex - SQL Query Builder
- Bcrypt - Password Hasher
- JWT - JSON Web Token
This project is meant to be run with Node.js v6.14.2, so make sure you have it installed and active when running this application. This project also relies on the yarn.lock
file to lock down dependency versions, so we recommend that you use yarn
instead of npm
to avoid "it works on my computer" bugs that are all too common with just a package.json
. Assuming you have nodenv
installed, you just need to install v6.14.2 and then install the dependencies:
$ nodenv install 6.14.2
$ cd api.pokedextracker.com
$ yarn
The .node-version
file should automatically switch the version for you whenever you cd
into the project directory.
This project uses PostgreSQL as its database, so you'll need to have the role and database setup. Assuming you already have it installed (either through brew
on OS X or apt-get
on Ubuntu), you can just run the following:
$ psql postgres
postgres=# CREATE ROLE "pokedex_tracker_user" CREATEDB CREATEUSER LOGIN;
$ createdb -O pokedex_tracker_user pokedex_tracker
$ yarn db:migrate
There are some secrets needed to run this repo locally, such as the Stripe API Key. Since no secrets are being checked in, you should copy .env.example
to .env
and populate it with all of the secrets listed there.
This repo doesn't include a way to completely load up the DB with all of the actual Pokemon data. That's only been loaded into the staging and production databases. For testing purposes and to make sure everything is functioning as expected, having that data isn't entirely necessary. You should be relying on tests and factories instead of the database state.
This project uses Mocha as the test runner, Chai BDD as our assertion library, and Istanbul to track code coverage. To run the tests locally, all you need to do is run:
$ yarn test
It will output the results of the test, and a coverage summary. To see a line-by-line breakdown of coverage to see what you missed, you should open ./coverage/lcov-report/index.html
.
Every merge into the master
branch on GitHub triggers a new build for a Docker image. That image will overwrite the latest
tag, and there will be an explicit tag with the first 7 characters of the commit hash. The server will be listening on port 8647 so if you run a container locally, make sure that traffic is forwarded to that port. For example:
$ docker run --rm --publish 8647:8647 --name pokedextracker-api pokedextracker/api.pokedextracker.com:latest