This repo contains all the backend code in use at Republik. For easier development the previously separate repos republik-backend, publikator-backend, assets-backend and backend-modules where merged into this monorepo.
For a guide on how to start the frontends see: docs/how-to-run
The components in this repo are split into two subfolders:
git clone [email protected]:orbiting/backends.git && cd backends
You must have Node.js (10+), yarn, docker and docker-compose installed (alternatively to docker you can install the external services natively).
The included docker-compose.yml starts all external-services. Currently that's: postgresql, redis, elasticsearch (and kibana).
The data is persisted in ./docker-data/
.
docker-compose up [-d]
We recommend you install the postgresql client tools on your machine to interact with the database. The tests scripts also depend on the clients being installed.
# linux
sudo apt install postgresql-client-12
When postgresql in running in docker client tools like psql
or createdb
/dropdb
don't automatically connect to it. They try to access postgresql via a local socket, when instead you want them to connect via network to localhost. To make your life easier, you can add the following environment variables to ~/.bashrc
/ ~/.zshrc
so the client tools connect to localhost per default.
export PGHOST=127.0.0.1
export PGUSER=postgres
show more
As an alternative to docker(-compose) you can install the external-services natively:
On macOS with homebrew:
brew install postgresql redis nvm elasticsearch
nvm install 14
nvm alias default 14
npm install -g [email protected]
brew services start postgresql
brew services start redis
brew services start elasticsearch
docker run -p 5601:5601 -e ELASTICSEARCH_HOSTS=http://host.docker.internal:9200 docker.elastic.co/kibana/kibana-oss:6.7.0
Note:
- Elasticsearch and Kibana versions must match, ckeck ES version at
http://localhost:9200/
ELASTICSEARCH_HOSTS
must be accessible within docker.
Copy the .env.example
files to .env
(in root and servers/assets/). The default values should be enough to get started.
cp .env.example .env
cp servers/assets/.env.example servers/assets/.env
yarn install
yarn dev:setup
yarn dev
This kicks on foreman which then launches all the servers locally.
All servers greets you with Cannot GET /
on the root route. The API server has a graphical API explorer available at /graphiql
:
In development environment variables are loaded from ./.env
.
No ENV variabeles are loaded from any file in production, you yourself are responsible to set all required ENVs in the production environment.
Checkout .env.example, servers/assets/.env.example for which ENVs are required and their descriptions. Check the packages' README for further config options.
You will quickly run into errors and limitations if you run with the example envs. You probably want to do the following two rather soon:
- MailChimp and Mandrill
MAILCHIMP_URL
,MAILCHIMP_API_KEY
,MANDRILL_API_KEY
in.env
MAILCHIMP_*
in.env
(less important)
- S3 Bucket
AWS_*
in the root.env
The following setup enables to start the servers (backends and republik-frontend) on one machine (A) and access it from another (B). This can come handy if you want to develop the backend on A and the app on B (where B can be a physical device).
Please not that due to how "Docker for Mac" works (docker is run in a hidden VM), it's not possible to bind containers to the host's network-interface, therefore this setup only works on linux.
- Get the IP of your machine in the local network, use it in the next step as
LOCAL_IP
ip addr
- Adapt hostnames in the environment variables:
- in
backends/.env
FRONTEND_BASE_URL=http://republik.test
ASSETS_SERVER_BASE_URL=http://assets.republik.test
LOCAL_IP=192.168.1.88
CORS_ALLOWLIST_URL=http://republik.test
COOKIE_DOMAIN=.republik.test
- in
republik-frontend/.env
API_URL=http://api.republik.test/graphql
API_WS_URL=ws://api.republik.test/graphql
API_ASSETS_BASE_URL=http://republik.test
PUBLIC_BASE_URL=http://republik.test
- Start the DNS-Server and reverse proxy:
docker-compose -f docker-compose-test-network.yml up [-d]
- bind: You now have a DNS server running locally. It resolves all requests of
*.republik.test
toLOCAL_IP
. - traefik: routes requests based on SNI (check: traefik.toml)
http://republik.test
->http://localhost:3010
http://api.republik.test
->http://localhost:5010
- Run backend services with docker (in
backends/
):
docker-compose up [-d]
- Refresh published articles, due to changed
ASSETS_SERVER_BASE_URL
(inbackends/
):
yarn pull:elasticsearch
redis-cli
> FLUSHALL
- Run the backend servers (in
backends/
):
yarn dev
- Run the frontend server (in
republik-frontend/
):
npm run dev
- Test You should be able to access http://api.republik.test/graphiql and http://republik.test
- To resolve the hostnames:
- Find the IP of Machine A, let's say its
192.168.1.88
- change your network config to use this IP as your DNS resolver.
- Adapt hostnames in the environment variables (in
app/.env.dev
):
API_URL=http://api.republik.test/graphql
API_WS_URL=ws://api.republik.test/graphql
FRONTEND_BASE_URL=http://republik.test
- Test
You should be able to access http://api.republik.test/graphiql and http://republik.test
- Setup simulators/emulators
At least the android emulator doesn't use the hosts dns resolver
- configure the DNS resolver manually (see step 1) inside the simulator
- test in the webbrowser that http://republik.test is accessible.
- run the app as usual (in
app/
)
yarn run-android
see packages/republik-crowdfundings/lib/scheduler/payments/README.md.
The source code and it's documentation is licensed under GNU AGPLv3+.