diff --git a/localenv/README.md b/localenv/README.md index 194b91225f..cd34a27802 100644 --- a/localenv/README.md +++ b/localenv/README.md @@ -100,6 +100,17 @@ pnpm localenv:compose:psql up pnpm localenv:compose:psql down --volumes ``` +The local environment consists of a primary Rafiki instance and a secondary Rafiki instance, each with +its own docker compose files ([Cloud Nine Wallet](./cloud-nine-wallet/docker-compose.yml), [Happy Life Bank](./happy-life-bank/docker-compose.yml)). +The primary Cloud Nine Wallet docker compose file (`./cloud-nine-wallet/docker-compose.yml`) includes the main Rafiki services `backend` and `auth`, as well +as the required data stores tigerbeetle (if enabled), redis, and postgres, so it can be run on its own. Furthermore, +both include the `local-signature-utils` signature generation app for Postman. +The secondary Happy Life Bank docker compose file (`./happy-life-bank/docker-compose.yml`) includes only the Rafiki services, not the data stores. It uses the +data stores created by the primary Rafiki instance so it can't be run by itself. +The `pnpm localenv:compose up` command starts both the primary instance and the secondary. + +#### Autopeering + If you want to start the local env and peer it automatically to rafiki.money, you can run the following commands: ``` @@ -109,14 +120,23 @@ pnpm localenv:autopeer:start pnpm localenv:autopeer:start:psql ``` -The local environment consists of a primary Rafiki instance and a secondary Rafiki instance, each with -its own docker compose files ([Cloud Nine Wallet](./cloud-nine-wallet/docker-compose.yml), [Happy Life Bank](./happy-life-bank/docker-compose.yml)). -The primary Cloud Nine Wallet docker compose file (`./cloud-nine-wallet/docker-compose.yml`) includes the main Rafiki services `backend` and `auth`, as well -as the required data stores tigerbeetle (if enabled), redis, and postgres, so it can be run on its own. Furthermore, -both include the `local-signature-utils` signature generation app for Postman. -The secondary Happy Life Bank docker compose file (`./happy-life-bank/docker-compose.yml`) includes only the Rafiki services, not the data stores. It uses the -data stores created by the primary Rafiki instance so it can't be run by itself. -The `pnpm localenv:compose up` command starts both the primary instance and the secondary. +Your local cloud nine rafiki instance will be peered automatically in this case with https://rafiki.money instance. +The required services will be exposed externally using [ngrok](https://www.npmjs.com/package/ngrok) and [tunnelmole](https://www.npmjs.com/package/tunnelmole) packages. +Ngrok is used to expose open-payments api and auth api. These apis require a https protocol for correctly validating the requests signatures and ngrok will add X-Forwarded-Proto to secure requests that helps koa to identify requests as secure. +Tunnelmole package is used for exposing externally ilp connector. + +There is no need for ngrok token in case you are planning to try out only the API requests. +In case you are looking to test the open payments example with the interaction flow, then the ngrok token should be provided in `~/cloud-nine-wallet/.env` file +as `NGROK_TOKEN={YOUR TOKEN}`. Ngrok does not serve html without providing the auth token. + +To use the postman collection examples - copy the created payment pointer and set it into `senderPaymentPointer` postman variable in `Remote Environment`. + +After stopping the script it is necessary to clear the environment using the command described in setup. This is necessary as on a new run of the scripts (with autopeeing or not) the payment pointer url will differ. + +``` +// tear down and remove volumes +pnpm localenv:compose down --volumes +``` ### Shutting down diff --git a/localenv/cloud-nine-wallet/docker-compose.yml b/localenv/cloud-nine-wallet/docker-compose.yml index c495989107..ead275dc7c 100644 --- a/localenv/cloud-nine-wallet/docker-compose.yml +++ b/localenv/cloud-nine-wallet/docker-compose.yml @@ -2,7 +2,7 @@ name: c9 services: cloud-nine-mock-ase: hostname: cloud-nine-wallet - image: rafiki-mock-ase + image: rafiki-mock-ase-10 build: context: ../.. dockerfile: ./localenv/mock-account-servicing-entity/Dockerfile @@ -17,7 +17,8 @@ services: PORT: 80 SEED_FILE_LOCATION: /workspace/seed.yml KEY_FILE: /workspace/private-key.pem - PUBLIC_HOST: ${CLOUD_NINE_PUBLIC_HOST:-'https://cloud-nine-wallet-backend'} + PUBLIC_HOST: ${CLOUD_NINE_PUBLIC_HOST:-https://cloud-nine-wallet-backend} + AUTH_SERVER_DOMAIN: ${CLOUD_NINE_AUTH_SERVER_DOMAIN:-http://localhost:3006} TESTNET_AUTOPEER_URL: ${TESTNET_AUTOPEER_URL} volumes: - ../cloud-nine-wallet/seed.yml:/workspace/seed.yml @@ -49,16 +50,16 @@ services: USE_TIGERBEETLE: ${USE_TIGERBEETLE-false} TIGERBEETLE_CLUSTER_ID: ${TIGERBEETLE_CLUSTER_ID-0} TIGERBEETLE_REPLICA_ADDRESSES: ${TIGERBEETLE_REPLICA_ADDRESSES-''} - AUTH_SERVER_GRANT_URL: ${CLOUD_NINE_AUTH_SERVER_DOMAIN:-'http://cloud-nine-wallet-auth:3006'} + AUTH_SERVER_GRANT_URL: ${CLOUD_NINE_AUTH_SERVER_DOMAIN:-http://cloud-nine-wallet-auth:3006} AUTH_SERVER_INTROSPECTION_URL: http://cloud-nine-wallet-auth:3007 - ILP_ADDRESS: ${ILP_ADDRESS:-'test.cloud-nine-wallet'} + ILP_ADDRESS: ${ILP_ADDRESS:-test.cloud-nine-wallet} STREAM_SECRET: BjPXtnd00G2mRQwP/8ZpwyZASOch5sUXT5o0iR5b5wU= - PUBLIC_HOST: ${CLOUD_NINE_PUBLIC_HOST:-'http://cloud-nine-wallet-backend'} - OPEN_PAYMENTS_URL: ${CLOUD_NINE_OPEN_PAYMENTS_URL:-'http://cloud-nine-wallet-backend'} + PUBLIC_HOST: ${CLOUD_NINE_PUBLIC_HOST:-http://cloud-nine-wallet-backend} + OPEN_PAYMENTS_URL: ${CLOUD_NINE_OPEN_PAYMENTS_URL:-http://cloud-nine-wallet-backend} WEBHOOK_URL: http://cloud-nine-wallet/webhooks EXCHANGE_RATES_URL: http://cloud-nine-wallet/rates REDIS_URL: redis://shared-redis:6379/0 - PAYMENT_POINTER_URL: ${CLOUD_NINE_PAYMENT_POINTER_URL:-'https://cloud-nine-wallet-backend/.well-known/pay'} + PAYMENT_POINTER_URL: ${CLOUD_NINE_PAYMENT_POINTER_URL:-https://cloud-nine-wallet-backend/.well-known/pay} ILP_CONNECTOR_ADDRESS: ${CLOUD_NINE_CONNECTOR_URL} depends_on: - shared-database @@ -79,7 +80,7 @@ services: NODE_ENV: ${NODE_ENV:-development} TRUST_PROXY: ${TRUST_PROXY} AUTH_DATABASE_URL: postgresql://cloud_nine_wallet_auth:cloud_nine_wallet_auth@shared-database/cloud_nine_wallet_auth - AUTH_SERVER_DOMAIN: ${CLOUD_NINE_AUTH_SERVER_DOMAIN:-'http://localhost:3006'} + AUTH_SERVER_DOMAIN: ${CLOUD_NINE_AUTH_SERVER_DOMAIN:-http://localhost:3006} depends_on: - shared-database shared-database: diff --git a/localenv/happy-life-bank/docker-compose.yml b/localenv/happy-life-bank/docker-compose.yml index fd9041e5ec..23dcef4ad4 100644 --- a/localenv/happy-life-bank/docker-compose.yml +++ b/localenv/happy-life-bank/docker-compose.yml @@ -15,7 +15,7 @@ services: PORT: 80 SEED_FILE_LOCATION: /workspace/seed.yml KEY_FILE: /workspace/private-key.pem - PUBLIC_HOST: ${HAPPY_LIFE_BANK_PUBLIC_HOST:-'https://happy-life-bank-backend'} + PUBLIC_HOST: ${HAPPY_LIFE_BANK_PUBLIC_HOST:-https://happy-life-bank-backend} volumes: - ../happy-life-bank/seed.yml:/workspace/seed.yml - ../happy-life-bank/private-key.pem:/workspace/private-key.pem @@ -43,16 +43,16 @@ services: USE_TIGERBEETLE: ${USE_TIGERBEETLE-false} TIGERBEETLE_CLUSTER_ID: ${TIGERBEETLE_CLUSTER_ID-0} TIGERBEETLE_REPLICA_ADDRESSES: ${TIGERBEETLE_REPLICA_ADDRESSES-''} - AUTH_SERVER_GRANT_URL: ${HAPPY_LIFE_BANK_AUTH_SERVER_DOMAIN:-'http://happy-life-bank-auth:3006'} + AUTH_SERVER_GRANT_URL: ${HAPPY_LIFE_BANK_AUTH_SERVER_DOMAIN:-http://happy-life-bank-auth:3006} AUTH_SERVER_INTROSPECTION_URL: http://happy-life-bank-auth:3007 ILP_ADDRESS: test.happy-life-bank STREAM_SECRET: BjPXtnd00G2mRQwP/8ZpwyZASOch5sUXT5o0iR5b5wU= - PUBLIC_HOST: ${HAPPY_LIFE_BANK_PUBLIC_HOST:-'http://happy-life-bank-backend'} + PUBLIC_HOST: ${HAPPY_LIFE_BANK_PUBLIC_HOST:-http://happy-life-bank-backend} WEBHOOK_URL: http://happy-life-bank/webhooks - OPEN_PAYMENTS_URL: ${HAPPY_LIFE_BANK_OPEN_PAYMENTS_URL:-'http://happy-life-bank-backend'} + OPEN_PAYMENTS_URL: ${HAPPY_LIFE_BANK_OPEN_PAYMENTS_URL:-http://happy-life-bank-backend} EXCHANGE_RATES_URL: http://happy-life-bank/rates REDIS_URL: redis://shared-redis:6379/1 - PAYMENT_POINTER_URL: ${HAPPY_LIFE_BANK_PAYMENT_POINTER_URL:-'https://happy-life-bank-backend/.well-known/pay'} + PAYMENT_POINTER_URL: ${HAPPY_LIFE_BANK_PAYMENT_POINTER_URL:-https://happy-life-bank-backend/.well-known/pay} depends_on: - cloud-nine-backend happy-life-auth: @@ -68,7 +68,7 @@ services: environment: NODE_ENV: development AUTH_DATABASE_URL: postgresql://happy_life_bank_auth:happy_life_bank_auth@shared-database/happy_life_bank_auth - AUTH_SERVER_DOMAIN: ${HAPPY_LIFE_BANK_AUTH_SERVER_DOMAIN:-'http://localhost:4006'} + AUTH_SERVER_DOMAIN: ${HAPPY_LIFE_BANK_AUTH_SERVER_DOMAIN:-http://localhost:4006} depends_on: - cloud-nine-auth happy-life-admin: diff --git a/localenv/mock-account-servicing-entity/app/lib/apiClient.ts b/localenv/mock-account-servicing-entity/app/lib/apiClient.ts index 9f0a43f28f..b3006a1a19 100644 --- a/localenv/mock-account-servicing-entity/app/lib/apiClient.ts +++ b/localenv/mock-account-servicing-entity/app/lib/apiClient.ts @@ -92,9 +92,10 @@ export class ApiClient { public static async endInteraction( interactId: string, - nonce: string + nonce: string, + authServerDomain: string ): Promise { - window.location.href = `http://localhost:3006/interact/${interactId}/${nonce}/finish` + window.location.href = `${authServerDomain}/interact/${interactId}/${nonce}/finish` return { isFailure: false } diff --git a/localenv/mock-account-servicing-entity/app/lib/parse_config.server.ts b/localenv/mock-account-servicing-entity/app/lib/parse_config.server.ts index bc89bb9aac..a0b0894b7d 100644 --- a/localenv/mock-account-servicing-entity/app/lib/parse_config.server.ts +++ b/localenv/mock-account-servicing-entity/app/lib/parse_config.server.ts @@ -56,6 +56,7 @@ export interface Config { key: crypto.KeyObject publicHost: string testnetAutoPeerUrl: string + authServerDomain: string } export const CONFIG: Config = { @@ -66,5 +67,6 @@ export const CONFIG: Config = { ), key: parseOrProvisionKey(process.env.KEY_FILE), publicHost: process.env.PUBLIC_HOST ?? '', - testnetAutoPeerUrl: process.env.TESTNET_AUTOPEER_URL ?? '' + testnetAutoPeerUrl: process.env.TESTNET_AUTOPEER_URL ?? '', + authServerDomain: process.env.AUTH_SERVER_DOMAIN || 'http://localhost:3006' } diff --git a/localenv/mock-account-servicing-entity/app/routes/shoe-shop.tsx b/localenv/mock-account-servicing-entity/app/routes/shoe-shop.tsx index 7e86e87bca..404e4c9318 100644 --- a/localenv/mock-account-servicing-entity/app/routes/shoe-shop.tsx +++ b/localenv/mock-account-servicing-entity/app/routes/shoe-shop.tsx @@ -1,7 +1,12 @@ -import { useLocation } from '@remix-run/react' +import { useLoaderData, useLocation } from '@remix-run/react' import { useEffect, useState } from 'react' import { ApiClient } from '~/lib/apiClient' import { parseQueryString } from '~/lib/utils' +import { CONFIG as config } from '~/lib/parse_config.server' + +export function loader() { + return config.authServerDomain +} function AuthorizedView({ thirdPartyName, @@ -16,6 +21,7 @@ function AuthorizedView({ interactId: string nonce: string }) { + const authServerDomain = useLoaderData() return ( <>
@@ -35,7 +41,7 @@ function AuthorizedView({