Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ db.*
venv*
node_modules
.vscode
.env
Resources/nginx/ssl/*
!Resources/nginx/ssl/*.sample.*
18 changes: 16 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
veekun_pokedex_repository = ../pokedex
local_config = --settings=config.local
docker_config = --settings=config.docker-compose
HASURA_GRAPHQL_ADMIN_SECRET=pokemon

.PHONY: help
.SILENT:

help:
@grep -E '^[a-zA-Z_-]+:.*?# .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?# "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
Expand Down Expand Up @@ -81,8 +83,20 @@ pull-veekun:
git -C ${veekun_pokedex_repository} checkout master-pokeapi
git -C ${veekun_pokedex_repository} pull

sync-from-veekun: pull pull-veekun # Copy data from ../pokedex to this repository
sync-from-veekun: pull pull-veekun # Copy data from ../pokedex to this repository
cp -a ${veekun_pokedex_repository}/pokedex/data/csv/. ./data/v2/csv

sync-to-veekun: pull pull-veekun # Copy data from this repository to ../pokedex
sync-to-veekun: pull pull-veekun # Copy data from this repository to ../pokedex
cp -a ./data/v2/csv/. ${veekun_pokedex_repository}/pokedex/data/csv

# read-env-file: # Exports ./.env into shell environment variables
# export `egrep -v '^#' .env | xargs`

hasura-export: # Export Hasura configuration
hasura md export --project graphql --admin-secret ${HASURA_GRAPHQL_ADMIN_SECRET}

hasura-apply: # Apply local Hasura configuration
hasura md apply --project graphql --admin-secret ${HASURA_GRAPHQL_ADMIN_SECRET}

hasura-get-anon-schema: # Dumps GraphQL schema
gq http://localhost:8080/v1/graphql --introspect > graphql/schema.graphql
78 changes: 50 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,7 @@

A RESTful API for Pokémon - [pokeapi.co](https://pokeapi.co)

## Join Us On Slack!

Have a question or just want to discuss new ideas and improvements? Hit us up on slack. Consider talking with us here before creating new issue.
This way we can keep issues here a bit more organized and helpful in the long run. Be excellent to each other :smile:

[Sign up](https://pokeapi-slack-invite.herokuapp.com/) easily!

Once you've signed up visit [PokéAPI on Slack](https://pokeapi.slack.com)

## Official Wrappers

* Node server-side [PokeAPI/pokedex-promise-v2](https://github.com/PokeAPI/pokedex-promise-v2) | _Auto caching_
* Browser client-side [PokeAPI/pokeapi-js-wrapper](https://github.com/PokeAPI/pokeapi-js-wrapper) | _Auto caching_
* Java/Kotlin [PokeAPI/pokekotlin](https://github.com/PokeAPI/pokekotlin)
* Python 3 [GregHilmes/pokebase](https://github.com/GregHilmes/pokebase) | _Auto caching_
* Python 2/3 [PokeAPI/pokepy](https://github.com/PokeAPI/pokepy) | _Auto caching_
* PHP [lmerotta/phpokeapi](https://github.com/lmerotta/phpokeapi) | _Auto caching, lazy loading_
* Ruby [rdavid1099/poke-api-v2](https://github.com/rdavid1099/poke-api-v2)
* .Net Standard [mtrdp642/PokeApiNet](https://github.com/mtrdp642/PokeApiNet) | _Auto caching_
* Go [mtslzr/pokeapi-go](https://github.com/mtslzr/pokeapi-go) | _Auto caching_
* Dart [prathanbomb/pokedart](https://github.com/prathanbomb/pokedart)
* Rust [lunik1/pokerust](https://gitlab.com/lunik1/pokerust) | _Auto caching_
* Spring Boot [dlfigueira/spring-pokeapi](https://github.com/dlfigueira/spring-pokeapi) | _Auto caching_
* Swift [kinkofer/PokemonAPI](https://github.com/kinkofer/PokemonAPI)
> Beta GraphQL support is rolling out! Check out the [GraphQL paragraph](#graphql) for more info.

## Setup [![pyVersion37](https://img.shields.io/badge/python-3.7-blue.svg)](https://www.python.org/download/releases/3.7/)

Expand Down Expand Up @@ -81,7 +58,7 @@ from data.v2.build import build_all
build_all()
```

Visit [localhost:8000/api/v2/](localhost:8000/api/v2/) to see the running API!
Visit [localhost:80/api/v2/](localhost:80/api/v2/) to see the running API!

Each time the build script is run, it will iterate over each table in the database, wipe it, and rewrite each row using the data found in data/v2/csv.

Expand All @@ -95,9 +72,9 @@ make wipe_db

## Docker and Compose

There is also a multi-container setup, managed by [Docker Compose](https://docs.docker.com/compose/). This setup allow you to deploy a production-like environment, with separate containers for each services.
There is also a multi-container setup, managed by [Docker Compose](https://docs.docker.com/compose/). This setup allows you to deploy a production-like environment, with separate containers for each services and is recommended if you need to simply spin up PokeAPI.

Start everything by simply
Start everything by

```sh
make docker-setup
Expand All @@ -113,14 +90,59 @@ docker-compose exec -T app sh -c 'echo "from data.v2.build import build_all; bui

Browse [localhost/api/v2/](http://localhost/api/v2/) or [localhost/api/v2/pokemon/bulbasaur/](http://localhost/api/v2/pokemon/bulbasaur/) on port `80`.

## GraphQL

<a href="ttps://github.com/hasura/graphql-engine">
<img width="100px" src="https://graphql-engine-cdn.hasura.io/img/powered_by_hasura_blue.svg" />
</a>

When you start PokeAPI with the above docker-compose setup, an [Hasura Engine](https://github.com/hasura/graphql-engine) server is started as well. It's possible to track all the PokeAPI tables and foreign keys by simply

```sh
# hasura cli needs to be installed and available in your $PATH: https://hasura.io/docs/latest/graphql/core/hasura-cli/install-hasura-cli.html
# hasura cli's version has to be v2.0.0-alpha.5
make hasura-apply
```

When finished browse http://localhost:8080 and you will find the admin console. The GraphQL endpoint will be hosted at http://localhost:8080/v1/graphql.

A free public GraphiQL console is browsable at the address https://beta.pokeapi.co/graphql/console/. The relative GraphQL endpoint is accessible at https://beta.pokeapi.co/graphql/v1beta

A set of examples are provided in the directory [/graphql/examples](./graphql/examples) of this repository.

## Official REST Wrappers

* Node server-side [PokeAPI/pokedex-promise-v2](https://github.com/PokeAPI/pokedex-promise-v2) | _Auto caching_
* Browser client-side [PokeAPI/pokeapi-js-wrapper](https://github.com/PokeAPI/pokeapi-js-wrapper) | _Auto caching_
* Java/Kotlin [PokeAPI/pokekotlin](https://github.com/PokeAPI/pokekotlin)
* Python 3 [GregHilmes/pokebase](https://github.com/GregHilmes/pokebase) | _Auto caching_
* Python 2/3 [PokeAPI/pokepy](https://github.com/PokeAPI/pokepy) | _Auto caching_
* PHP [lmerotta/phpokeapi](https://github.com/lmerotta/phpokeapi) | _Auto caching, lazy loading_
* Ruby [rdavid1099/poke-api-v2](https://github.com/rdavid1099/poke-api-v2)
* .Net Standard [mtrdp642/PokeApiNet](https://github.com/mtrdp642/PokeApiNet) | _Auto caching_
* Go [mtslzr/pokeapi-go](https://github.com/mtslzr/pokeapi-go) | _Auto caching_
* Dart [prathanbomb/pokedart](https://github.com/prathanbomb/pokedart)
* Rust [lunik1/pokerust](https://gitlab.com/lunik1/pokerust) | _Auto caching_
* Spring Boot [dlfigueira/spring-pokeapi](https://github.com/dlfigueira/spring-pokeapi) | _Auto caching_
* Swift [kinkofer/PokemonAPI](https://github.com/kinkofer/PokemonAPI)

## Donations

Help to keep PokéAPI running! If you're using PokéAPI as a teaching resource or for a project, consider sending us a $10 donation to help keep the service up. We get almost 20 million requests a month!
Help to keep PokéAPI running! If you're using PokéAPI as a teaching resource or for a project, consider sending us a $10 donation to help keep the service up. We get 60 million requests a month!

Thank you to all our backers! [Become a backer](https://opencollective.com/pokeapi#backer)

<a href="https://opencollective.com/pokeapi#backers" target="_blank"><img src="https://opencollective.com/pokeapi/backers.svg?width=890"></a>

## Join Us On Slack!

Have a question or just want to discuss new ideas and improvements? Hit us up on slack. Consider talking with us here before creating new issue.
This way we can keep issues here a bit more organized and helpful in the long run. Be excellent to each other :smile:

[Sign up](https://pokeapi-slack-invite.herokuapp.com/) easily!

Once you've signed up visit [PokéAPI on Slack](https://pokeapi.slack.com)

## Contributing

This project exists thanks to all the people who [contribute](https://github.com/PokeAPI/pokeapi/blob/master/CONTRIBUTING.md)
Expand Down
31 changes: 31 additions & 0 deletions Resources/compose/docker-compose-prod-graphql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
version: '2.4'
services:
db:
environment:
POSTGRES_PASSWORD: "${POSTGRES_PASSWORD}"
POSTGRES_USER: "${POSTGRES_USER}"

app:
env_file: .env

web:
volumes:
- graphiql:/public-console:ro

graphql-engine:
environment:
HASURA_GRAPHQL_DATABASE_URL: "postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@db:5432/pokeapi"
HASURA_GRAPHQL_ADMIN_SECRET: "${HASURA_GRAPHQL_ADMIN_SECRET}"

graphiql:
image: pokeapi/graphiql:1.0.1
command: sh -c 'cp -a /app/static/. /transfer/ && tail -f /etc/passwd'
volumes:
- graphiql:/transfer
depends_on:
- graphql-engine

volumes:
graphiql:

# docker-compose -f docker-compose.yml -f Resources/compose/docker-compose-graphql.yml up
2 changes: 0 additions & 2 deletions Resources/docker/web/Dockerfile

This file was deleted.

92 changes: 64 additions & 28 deletions Resources/nginx/nginx.conf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
worker_processes 4; # 80$ droplet, so 4 core enabled
worker_processes 2;

events {
worker_connections 8096; # accepted incoming connections*2
worker_connections 4096;
multi_accept on; # accept each connection as soon as you can
accept_mutex off;
use epoll;
Expand All @@ -17,75 +17,111 @@ http {

client_body_buffer_size 10K; # raise the threshold by which requests are written to HDD instead of RAM
client_header_buffer_size 2k;
client_max_body_size 8m; # we dont accept requests larger that 8mb, probably you are DoSing us
client_max_body_size 8m; # we dont accept requests larger that 8mb

sendfile on;
tcp_nopush on;
tcp_nodelay on;

keepalive_timeout 5;

gzip on; # enable zipping files
gzip_vary on;
gzip_min_length 5120; # enable it only for medium-big files (slowbro size is 7000)
gzip_proxied expired no-cache no-store private auth;
gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml application/json;
gzip on;
gzip_disable "msi6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_min_length 256;
gzip_types application/atom+xml application/geo+json application/javascript application/x-javascript application/json application/ld+json application/manifest+json application/rdf+xml application/rss+xml application/xhtml+xml application/xml font/eot font/otf font/ttf image/svg+xml text/css text/javascript text/plain text/xml;

upstream pokeapi_upstream {
# 'app' is the Django container name in Docker
# DO NOT EDIT IT ALONE or it'll break docker-compose
server app:8000 fail_timeout=0;
}

upstream graphql_upstream {
server graphql-engine:8080 fail_timeout=0;
}

geo $limit {
default 1;
10.0.0.0/8 0;
192.168.0.0/24 0;
}

map $limit $limit_key {
0 "";
1 $binary_remote_addr;
}

limit_req_zone $limit_key zone=graphqlDefaultLimit:50m rate=1r/m;
limit_conn_zone $binary_remote_addr zone=addr:20m;

server {
listen 80 deferred;
server_name _;
root /code;

include /ssl/ssl.conf*;

client_body_timeout 5s;
client_header_timeout 5s;
limit_conn addr 10;

root /code;

location /media/ {
root /code;
autoindex off;
# Admin console
location /graphql/admin/ {
expires 1m; # client-side caching, one minute for each API resource
add_header Cache-Control "public";
add_header Pragma public;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://graphql_upstream/;
}

location /static/ {
alias /code/assets/;
autoindex off;
location /graphql/console {
alias /public-console/;
index index.html;
try_files $uri $uri/ /index.html =405;
}
location ~* \.(jpg|jpeg|gif|png|css|js|ico|xml)$ { # cache all these extensions for 5 days, disable logging
access_log off;
log_not_found off;
expires 5d;

location /graphql/v1beta {
limit_req zone=graphqlDefaultLimit burst=100 nodelay;
limit_req_status 429;
expires 1m; # client-side caching, one minute for each API resource
add_header Cache-Control "public";
add_header Pragma public;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://graphql_upstream/v1/graphql;
}

location /api/ {
expires 1m; # client-side caching, one minute for each API resource
add_header Cache-Control "public";
add_header Pragma public;

proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;

proxy_redirect off;

proxy_pass http://pokeapi_upstream;
}

location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;

proxy_redirect off;

proxy_pass http://pokeapi_upstream;
}
}
Expand Down
14 changes: 14 additions & 0 deletions Resources/nginx/ssl/ssh.sample.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copy this file to ssl.conf, add certificate and private key to enable ssl

listen 443 ssl http2;
listen [::]:443 ssl http2;

ssl_certificate /ssl/cert.cer;
ssl_certificate_key /ssl/key.key;
ssl_session_timeout 1d;
ssl_session_cache shared:MozSSL:10m;
ssl_session_tickets off;

ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;
ssl_prefer_server_ciphers off;
11 changes: 11 additions & 0 deletions apollo.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = {
client: {
service: {
name: "pokeapi",
url: "http://localhost:8080/v1/graphql",
headers: {
"x-hasura-admin-secret": "pokemon",
},
},
},
};
7 changes: 5 additions & 2 deletions config/docker-compose.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# Docker settings
import os
from .settings import *

DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql_psycopg2",
"NAME": "pokeapi",
"USER": "ash",
"PASSWORD": "pokemon",
"USER": os.environ.get("POSTGRES_USER", "ash"),
"PASSWORD": os.environ.get("POSTGRES_PASSWORD", "pokemon"),
"HOST": "db",
"PORT": 5432,
}
Expand All @@ -25,3 +26,5 @@

DEBUG = False
TASTYPIE_FULL_DEBUG = False

ALLOWED_HOSTS = ["*"]
Loading