An open API service indexing awesome lists of open source software.

https://github.com/peroxy/pokemon-catch-guide-api

API for the Pokemon Catching Guide website
https://github.com/peroxy/pokemon-catch-guide-api

Last synced: 12 months ago
JSON representation

API for the Pokemon Catching Guide website

Awesome Lists containing this project

README

          

# Pokemon Catching Guide API

Pokemon Catching Guide API is a simple REST API built with NodeJS and Express.

It is used by the frontend website located in the repository [Pokemon Catching Guide Website](https://github.com/peroxy/pokemon-catch-guide-website).

It serves data generated by the CSV encounter generator ([Pokemon Catch Guide](https://github.com/peroxy/pokemon-catch-guide)).
The CSV files are parsed and inserted into a local Sqlite database for easier usage.

## Installation

Use the package manager [npm](https://www.npmjs.com/) to install the API.

```shell
cd pokemon-catch-guide-api
npm install
```

## Usage

Please look at the `package.json` scripts section to run a specific script:

```json
"scripts": {
"build": "tsc",
"prestart": "npm run build",
"start": "node .",
"live-reload": "nodemon src/app.ts",
"insert-from-csv-to-database": "ts-node ./src/db/csv_data/csv_inserter.ts"
}
```

- Run the REST API:
```shell
npm run start
```
- Run the REST API with live reload:
```shell
npm run live-reload
```
- Run CSV inserter (inserts CSV data into local sqlite database):
```shell
npm run insert-from-csv-to-datbase
```

### API

The API runs on port 8080 if environment variable `SERVER_PORT` is not specified.

Every API route requires a bearer token to be specified in the `Authorization` header.
For example, if your `NODE_ENV` environment variable is set to `development` you may use the default token `pokemon`:
- HTTP Header: `Authorization: Bearer pokemon`

On `production` environment you will have to specify an environment variable `API_SECRET_HASH` that represents your bcrypt hashed secret.

## Deployment
```shell
# ssh into server

# install letsencrypt certificate
sudo snap install core; sudo snap refresh core
sudo snap install --classic certbot
sudo ln -s /snap/bin/certbot /usr/bin/certbot
sudo certbot certonly --standalone
# check if renewal works
sudo certbot renew --dry-run

# update api.conf and docker-compose.yml with correct /etc/letsencrypt path and domain

mkdir pokemon-catch-guide && cd pokemon-catch-guide
wget https://raw.githubusercontent.com/peroxy/pokemon-catch-guide-api/master/docker-compose.yml
wget https://raw.githubusercontent.com/peroxy/pokemon-catch-guide-api/master/src/db/pokemon.db
wget https://raw.githubusercontent.com/peroxy/pokemon-catch-guide-api/master/nginx/conf.d/api.conf -O ./nginx/conf.d/api.conf

# create .env file
touch .env && nano .env
# insert API_SECRET_HASH='bcrypt encrypted hash' < very important that you take the password and then encrypt it with bcrypt, needs to be the hash!

docker-compose up -d
```

### Troubleshooting

#### PEM_read_bio_X509_AUX() failed (SSL: error:0909006C:PEM routines:get_name:no start line:Expecting: TRUSTED CERTIFICATE)

If nginx exits and logs this error the docker volume isn't working correctly - but it's probably just docker service being stupid.
**Restart the server** - docker-compose.yml is 100% correct.

## Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

## License
[Apache License 2.0](http://www.apache.org/licenses/)