A public API for the web app, and mobile apps to consume.
If you are reading this, thanks for stopping by. You may be familiar with the Redadalertas project.
This project is part of that. This repo will house the code to make the public facing API.
https://cosecha.github.io/redadalertas-api/
Make sure you have the following installed on your computer
- Node.js (latest)
- Docker (or the Docker for Mac app)
- Git
- Mongo
- Yarn
- Xcode Command Line Tools:
xcode-select --install
(required to properly install the bcrypt package)
- Clone the repository
- In /, copy over the environment variables:
cp src/.env.example src/.env
- Figure out what your DB_CONNECTION_STRING_DOCKER should be in src/.env and modify it if necessary (NOTE: Docker for Mac users can use
DB_CONNECTION_STRING_DOCKER=mongodb://docker.for.mac.localhost:27017/redadalertas
) - If you're using Docker for Mac, make sure the app is running
- Make sure your MongoDB is up to date (
brew upgrade mongodb-community
; you may have to clear /data/db) - Run MongoDB service:
brew services start mongodb-community
- Open a terminal for MongoDB:
mongod
- Install Node modules specified by package.json in the /src directory:
cd src
, thenyarn install
- Create local Mongo database with test data:
yarn run bootstrap
in the /src directory - Set up Docker:
docker build .
in the / directory (should end with "Successfully built [image ID]") - Run Docker container from built image and forward traffic from localhost:
docker run -p 127.0.0.1:8080:8080 -it [image id]
- You should now be able to receive requests from localhost:8080/api
- To shut down server:
Ctrl + c
in server terminal (available since you used -it flag on docker run), ordocker stop [container ID]
(rundocker ps
to get list of active container IDs) - To shut down database cleanly:
brew services stop mongodb-community
- To shut down mongod cleanly:
Ctrl + c
in mongod terminal, or open the command interface:mongo
-->use admin
-->db.shutdownServer()
-->exit
You can run direct Yarn commands whenever you make changes.
Instead of using Docker in steps 10 and 11 above:
yarn run build
: compiles the app into /buildyarn start
: starts the server (Ctrl + c
still stops it)
We use Yarn instead of NPM commands in the /src directory.
yarn install
: installs Node modulesyarn run build
: compiles the app into /buildyarn start
: starts the serveryarn test
: performs testingyarn run lint
: runs the linteryarn run bootstrap
: populates your local mongo db with sample data (warning: this will reset your database)