GraphQL API server for clients like rumors-site and rumors-line-bot
Clone or download
MrOrz Merge pull request #98 from cofacts/41-create-reply
Scrap URLs when replies are submitted
Latest commit 756ec07 Jul 25, 2018
Permalink
Failed to load latest commit information.
config Make error logs less verbose Feb 16, 2018
src CreateReply now also scraps URL in its text & references Jul 15, 2018
static Use apollo server instead, and add an index that is more informative. Dec 16, 2016
test Update rumors-db for urls field fix Jul 10, 2018
.babelrc Use npm5 instead of yarn. Jan 13, 2018
.dockerignore Staging build command & revise Dockerfile to remove yarn Feb 16, 2018
.eslintignore Switch linter to prettier May 3, 2017
.eslintrc.js Switch linter to prettier May 3, 2017
.gitignore Adding esdata directory for easier seed feeding Feb 17, 2018
.gitmodules Update gitmodules to use https to avoid ssh key issue Feb 13, 2017
.travis.yml Remove yarn related statement in travis and README Feb 16, 2018
Dockerfile Update all dependencies Jul 1, 2018
LICENSE Squashed 'test/rumors-db/' content from commit db7ea44 Feb 1, 2017
README.md Update rumors-test-db script Jul 9, 2018
docker-compose.yml Upgrade docker-compose elasticsearch version and switch to oss version Jul 7, 2018
g0v.json Add g0v.json Apr 5, 2017
jsconfig.json Make vscode happy Jan 17, 2018
package-lock.json Merge branch 'master' into 41-url-preview Jul 9, 2018
package.json Merge branch 'master' into 41-url-preview Jul 9, 2018
process-dev.json Update docker-compose and process.json to fix constant-restart problem Feb 17, 2018
process.json Update docker-compose and process.json to fix constant-restart problem Feb 17, 2018
renovate.json Update renovate.json Mar 29, 2018

README.md

rumors-api

Build Status Coverage Status

GraphQL API server for clients like rumors-site and rumors-line-bot

Development

Prerequisite

First-time setup

After cloning this repository & cd into project directory, then install the dependencies.

$ git clone --recursive git@github.com:MrOrz/rumors-api.git # --recursive for the submodules
$ cd rumors-api
$ npm i

If you want to test OAuth2 authentication, you will need to create config/local-development.js (already in .gitignore) with the following content:

module.exports = {
  FACEBOOK_APP_ID: '⋯⋯',
  FACEBOOK_SECRET: '⋯⋯',
  TWITTER_CONSUMER_KEY: '⋯⋯',
  TWITTER_CONSUMER_SECRET: '⋯⋯',
  GITHUB_CLIENT_ID: '⋯⋯',
  GITHUB_SECRET: '⋯⋯',
};

Please apply for the keys in Facebook, Twitter and Github respectively.

Start development servers

$ mkdir esdata # For elasticsearch DB
$ docker-compose up

This will:

  • rumors-api server on http://localhost:5000. It will be re-started when you update anyfile.
  • Kibana on http://localhost:6222.
  • ElasticSearch DB on http://localhost:62222.

To stop the servers, just ctrl-c and all docker containers will be stopped.

Populate ElasticSearch with data

Ask a team member to send you nodes directory, then put the nodes directory right inside the esdata directory created in the previous step, then restart the database using:

$ docker-compose restart db

Detached mode & Logs

If you do not want a console occupied by docker-compose, you may use detached mode:

$ docker-compose up -d

Access the logs using:

$ docker-compose logs api     # `api' can also be `db', `kibana'.
$ docker-compose logs -f api  # Tail mode

About test/rumors-db

This directory is managed by git submodule. Use the following command to update:

$ npm run rumors-db:pull

Lint

# Please check lint before you pull request
$ npm run lint
# Automatically fixes format error
$ npm run lint:fix

Test

To prepare test DB, first start an elastic search server on port 62223:

$ docker run -d -p "62223:9200" --name "rumors-test-db" docker.elastic.co/elasticsearch/elasticsearch-oss:6.3.0
# If it says 'The name "rumors-test-db" is already in use',
# Just run:
$ docker start rumors-test-db

Then run this to start testing:

$ npm t

If you get "Elasticsearch ERROR : DELETE http://localhost:62223/replies => socket hang up", please check if test database is running. It takes some time for elasticsearch to boot.

If you want to run test on a specific file (ex: src/xxx/__tests__/ooo.js), run:

$ npm t -- src/xxx/__tests__/ooo.js

When you want to update jest snapshot, run:

$ npm t -- -u

Deploy

Build docker image. The following are basically the same, but with different docker tags.

# Production build
$ npm run build

# Staging build
$ npm run build:staging

Run the docker image on local machine, then visit http://localhost:5000. (To test functions involving DB, ElasticSearch DB must work as config/default.js specified.)

$ docker run --rm -it -p 5000:5000 mrorz/rumors-api

Push to dockerhub

# Production
$ docker push mrorz/rumors-api:latest

# Staging
$ docker push mrorz/rumors-api:staging