Skip to content
This repository has been archived by the owner on Apr 6, 2022. It is now read-only.

Latest commit

 

History

History
254 lines (168 loc) · 8 KB

README.md

File metadata and controls

254 lines (168 loc) · 8 KB

[DEPRECATED] @orbiting/backends Build Status Coverage Status

⚠️ This repository together with others has been merged into the republik/plattform monorepo. Let's continue the journey there. ⚠️

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

Components

The components in this repo are split into two subfolders:

  • servers: contains runnable servers
  • packages: contains code shared between the servers

How to run / Development

1. Clone

git clone [email protected]:orbiting/backends.git && cd backends

2. Prerequisites

You must have Node.js (10+), yarn, docker and docker-compose installed (alternatively to docker you can install the external services natively).

Docker

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]
Postgresql in docker

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

alternativ: install natively

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 Kibana accessing native 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.

2. ENVs

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

3. Install

yarn install

4. Setup

yarn dev:setup

5. Run

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:

Next steps

more about ENVs

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:

  1. MailChimp and Mandrill
    • MAILCHIMP_URL, MAILCHIMP_API_KEY, MANDRILL_API_KEY in .env
    • MAILCHIMP_* in .env (less important)
  2. S3 Bucket
    • AWS_* in the root .env

Special setup: develop on two hosts

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.

Machine A (servers)

  1. Get the IP of your machine in the local network, use it in the next step as LOCAL_IP
ip addr
  1. 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
  1. 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 to LOCAL_IP.
  • traefik: routes requests based on SNI (check: traefik.toml)
    • http://republik.test -> http://localhost:3010
    • http://api.republik.test -> http://localhost:5010
  1. Run backend services with docker (in backends/):
docker-compose up [-d]
  1. Refresh published articles, due to changed ASSETS_SERVER_BASE_URL (in backends/):
yarn pull:elasticsearch
redis-cli
> FLUSHALL
  1. Run the backend servers (in backends/):
yarn dev
  1. Run the frontend server (in republik-frontend/):
npm run dev
  1. Test You should be able to access http://api.republik.test/graphiql and http://republik.test

Machine B (app)

  1. 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.
  1. 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
  1. Test

You should be able to access http://api.republik.test/graphiql and http://republik.test

  1. 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

Postfinance Import

see packages/republik-crowdfundings/lib/scheduler/payments/README.md.

Licensing

The source code and it's documentation is licensed under GNU AGPLv3+.