moonpay-api v0.1.0
MoonPay API
Local development
First, make sure you have Node.js, PostgreSQL and Redis installed on your machine.
# Install dependencies
$ npm install
# Setup environment variables (fill the created .env file)
$ cp .env.example .env
# (optional) You can use Docker to host postgres & redis databases instead of installing them locally.
# If you choose this option, an empty `moonpay` database will be created automatically on the first launch
$ npm run db:up
# (optional) Create database (only needed when using locally installed databases instead of Docker container)
$ createdb moonpay
# (optional) Initialize algolia environment for local development
$ npm run sync:algolia:init-dev
# Run DB migrations
$ npm run db:migrate
# Run DB seeds
$ npm run db:seed
# Serve public API with hot reload
$ npm run dev:public-api
# Serve private API with hot reload
$ npm run dev:private-api
# Start local worker (needed for exchange rates when using local widget)
$ npm run dev:worker
# Build for production
$ npm run build
Algolia
Algolia uses dynamic environments based on the configuration set in the API (prod, staging, mk, vf etc...).
This means, that you can no longer use "naked" index names - customers
. Instead, you have to construct all names
using a helper method from lib/algolia:prefixIndexName
const searchIndex = algoliaClient.initIndex(
prefixIndexName('customers'),
);
This ensures that the correct index is queried and updated. All API keys are also locked to your personalized env, ensuring that you can't query the wrong index by accident.
❗ If you're planning on running the API locally, make sure that your algolia environment is set up correctly by adding
ALGOLIA_ENV={insert_your_initials_or_whatever_here}
tn your .env and runningnpm run sync:algolia:init-dev
Tests
Database is dropped and reconstructed only when a new server instance is created with preparePublicServer({ migrate: true, seeds: true })
.
This usually happens only once per test file.
Have fun!
5 years ago