Getting started
Our API requires the following environment variables to be stored in a .env file in the root directory. Contact a team member for sane defaults.
Environmental Variables
SESSION_SECRET
: String for hashing passwordsSERVICE_SECRET
: String for hashing passwordsSALE_FACTORY_ADDRESS
: Address of the deployed Token Sale Factory ContractPURCHASE_FACTORY_ADDRESS
: Address of the deployed Token Purchase Factory ContractINFURA_PROJECT_ID
: API Key for the Infura Blockchain connectionS3_BUCKET
: Name of the S3 buckets for documentsS3_ENDPOINT
: For prod, this should be set toimg.meridio.co
, for all other environments should be set toimg-dev.meridio.co
AWS_ACCESS_KEY_ID
: AWS Key ID for S3 bucketAWS_SECRET_ACCESS_KEY
: AWS Key for S3 bucketMAILGUN_API_KEY
: API for email sendingSTREAM_API_KEY
: Stream Key for notificationsSTREAM_API_SECRET
: Stream SecretSTREAM_API_APP_ID
: Stream App IDON_BOARDING_SECRET
: hashing for registration tokensEMAIL_VERIFICATION_SECRET
: hashing email verification tokensPOSTGRES_HOST
: Hostname of your PostgresDBPOSTGRES_USER
: UsernamePOSTGRES_PW
: Password pwPOSTGRES_DB
: DB nameREDIS_PORT
: (optional) Port to connect to Redis, defaults to6379
REDIS_HOST
: (optional) Hostname of your Redis, defaults to127.0.0.1
REDIS_PASSWORD
: (optional) Password to connect to Redis, defaults toNULL
SENTRY_KEY
: (optional) Currently only reports uncaught errorsBLOCKCHAIN_ENV
: Currently supporting rinkeby, ropsten, mainnet, ganache
Development Only
USER_EMAIL
: If you'd like to prepopulate your user's wallet address, enter in your email address here.USER_ADDRESS_HASH
: IfUSER_EMAIL
is found, this address hash will be added as a wallet for that user.BLOCKCHAIN_SERVICE
: local blockchain serviceSEQUELIZE_TIMEOUT
: (optional) SQL statement timeout (ms) override (default: 5000)SEQUELIZE_LOGGING
: (optional) SQL logging options override (0 or 1, default 0, no sql logging);HTTP_LOGGING
: (optional) Add apache style http logging via Morgan - always on in development environments (0 or 1 when deployed, default 0, no http logging);
Running the Full Stack Application
Method 1: Docker Containers
To bring up the entire Meridio Application locally, run the following command:
npm run containers:full
This command uses relative paths, so you must also checkout the frontend and blockchain service repositories as well.
Running the API Stand Alone
Method 1: Docker Containers
The first time you run the application you must first build the images with the following command:
docker-compose build
Subsequent launches only require docker-compose up command.
docker-compose up
Method 2: Host Operating System
To run the application locally without docker, execute the following command:
npm run api-dev
Development
Development in Containers (with hot reload)
To simulate our production environment we use containers in development as well, reloading the application every time changes are detected in the the api/
directory.
npm run containers:watch
Testing
Testing in Docker (with hot reload)
Similarly to the application hot reloading in the previous section, the following command will automatically rerun the test suite when it detects code changes.
npm run test:containers:watch
Single Test Run in Docker
To simulate a single run through the test suite use the following command.
npm run test:containers
Testing Locally
To test locally run the following command:
npm run test
Libraries Used
- Bull - is a redis based queue for Node. It allows to create and manage job queues as the primary method of communication with the Blockchain Service.
- Factory-girl - For any given test, we need some data about which to make an assertion after performing some operation. This library is a fixture replacement with a Sequelize interface. Please note using this package can introduce a DB dependency.
- Finale - makes it easy to create flexible REST endpoints and controllers from Sequelize models in our Express app.
- Mailgun - Email API for sending transactional emails from within our application.
- Mocha with Chai - is a feature-rich JavaScript test framework running on Node.js and in the browser, making asynchronous testing simple/ Mocha tests run serially, allowing for flexible and accurate reporting, while mapping uncaught exceptions to the correct test cases.
- Raven - is an open source package from Sentry that helps developers monitor and fix crashes in real time.
- Sequelize- is a promise-based ORM for Node.js v4 and up. It supports the dialects PostgreSQL, MySQL, SQLite and MSSQL and features solid transaction support, relations, read replication and more.
- Sinon - is a standalone test spies, stubs and mocks for JavaScript.
- Stream - allows us to build scalable news feeds & activity streams. This is currently utilized during our in-app notifications.
Miscellaneous
Postman
We use postman for teams for testing our API directly. For access to our library of prewritten tests, use the following link.
Launch Exchange/Dai/Token Contracts locally
- Launch Ganache
truffle compile
truffle migrate --network development --reset