Hopp til hovedinnhold

Miljøvariabler

Hvert ChurchApps-prosjekt bruker en .env-fil for lokal konfigurasjon. Hvert prosjekt inkluderer en eksempelfil som du kopierer og tilpasser. Denne siden dekker miljøvariablene for API-er, webapper og mobilapper, inkludert hvordan du velger mellom staging og lokale API-mål.

Før du begynner

  • Installer forutsetningene for prosjektet ditt
  • Klon prosjektrepositoriet du ønsker å jobbe med
  • Gjennomgå Prosjektoversikten for å forstå hvilke API-moduler prosjektet ditt trenger

Generelt mønster

  1. Se etter dotenv.sample.txt eller .env.sample i prosjektroten.
  2. Kopier den til .env.
  3. Rediger verdiene etter behov.
# Eksempel for et prosjekt med .env.sample
cp .env.sample .env

# Eksempel for et prosjekt med dotenv.sample.txt
cp dotenv.sample.txt .env
Advarsel

Aldri commit .env-filer til versjonskontroll. De inneholder hemmeligheter som databaselegitimasjon, API-nøkler og JWT-hemmeligheter. Alle ChurchApps-prosjekter inkluderer .env i .gitignore, men dobbeltsjekk alltid før du committer.

Velge et API-mål

Den viktigste beslutningen er hvor frontenden din peker for API-kall. Det er to alternativer:

Alternativ 1: Staging-API-er (anbefalt for frontend-utvikling)

Bruk det delte staging-miljøet. Ingen lokalt API- eller databaseoppsett er nødvendig.

# Basis-URL-mønster
https://api.staging.churchapps.org/{modul}

# Eksempel på modul-URL-er
https://api.staging.churchapps.org/membership
https://api.staging.churchapps.org/attendance
https://api.staging.churchapps.org/content
https://api.staging.churchapps.org/giving
https://api.staging.churchapps.org/messaging
https://api.staging.churchapps.org/doing

Alternativ 2: Lokalt API

Kjør Api-prosjektet på maskinen din. Krever MySQL 8.0+ med databaser opprettet for hver modul. Se guiden for lokalt API-oppsett.

# Basis-URL-mønster
http://localhost:8084/{modul}

# Eksempel på modul-URL-er
http://localhost:8084/membership
http://localhost:8084/attendance
http://localhost:8084/content
http://localhost:8084/giving
http://localhost:8084/messaging
http://localhost:8084/doing

API-miljøvariabler

Kjerne-Api-prosjektet (.env.sample) har mest konfigurasjon. Her er de viktigste variablene:

Delte innstillinger

VariabelBeskrivelseEksempel
ENVIRONMENTKjøremiljødev
SERVER_PORTHTTP-port for lokal utviklingsserver8084
ENCRYPTION_KEY192-bit krypteringsnøkkel for sensitive dataaSecretKeyOfExactly192BitsLength
JWT_SECRETHemmelighet for signering av JSON Web Tokensjwt-secret-dev
FILE_STOREHvor opplastede filer lagres (disk eller s3)disk
CORS_ORIGINTillatte CORS-opprinnelser (* for lokal utvikling)*

Databasetilkoblinger

Hver API-modul har sin egen MySQL-database og tilkoblingsstreng:

VariabelDatabase
MEMBERSHIP_CONNECTION_STRINGmysql://root:password@localhost:3306/membership
ATTENDANCE_CONNECTION_STRINGmysql://root:password@localhost:3306/attendance
CONTENT_CONNECTION_STRINGmysql://root:password@localhost:3306/content
GIVING_CONNECTION_STRINGmysql://root:password@localhost:3306/giving
MESSAGING_CONNECTION_STRINGmysql://root:password@localhost:3306/messaging
DOING_CONNECTION_STRINGmysql://root:password@localhost:3306/doing
Tips

Oppdater root:password med din faktiske MySQL-legitimasjon. Hver database må opprettes før du kjører API-et. Bruk npm run initdb for å opprette skjemaet for alle moduler, eller npm run initdb:membership for en enkelt modul.

WebSocket-innstillinger

VariabelBeskrivelseEksempel
SOCKET_PORTPort for WebSocket-serveren8087
SOCKET_URLWebSocket-URL for klienter å koble tilws://localhost:8087

Webapp-miljøvariabler

B1Admin (React + Vite)

Eksempelfil: .env.sample

VariabelBeskrivelseEksempel (staging)
REACT_APP_STAGEMiljønavndemo
PORTUtviklingsserverport3101
REACT_APP_MEMBERSHIP_APIMembership API-URLhttps://api.staging.churchapps.org/membership
REACT_APP_ATTENDANCE_APIAttendance API-URLhttps://api.staging.churchapps.org/attendance
REACT_APP_GIVING_APIGiving API-URLhttps://api.staging.churchapps.org/giving
REACT_APP_CONTENT_ROOTURL for innholdsleveringhttps://content.staging.churchapps.org
REACT_APP_GOOGLE_ANALYTICSGoogle Analytics-ID (valgfri)UA-123456789-1

For lokal API-utvikling, fjern kommentar og bruk localhost-variantene:

REACT_APP_MEMBERSHIP_API=http://localhost:8084/membership
REACT_APP_ATTENDANCE_API=http://localhost:8084/attendance
REACT_APP_GIVING_API=http://localhost:8084/giving
REACT_APP_CONTENT_API=http://localhost:8084/content
REACT_APP_DOING_API=http://localhost:8084/doing
REACT_APP_MESSAGING_API=http://localhost:8084/messaging

B1App (Next.js)

Eksempelfil: .env.sample

VariabelBeskrivelseEksempel (staging)
NEXT_PUBLIC_MEMBERSHIP_APIMembership API-URLhttps://api.staging.churchapps.org/membership
NEXT_PUBLIC_ATTENDANCE_APIAttendance API-URLhttps://api.staging.churchapps.org/attendance
NEXT_PUBLIC_GIVING_APIGiving API-URLhttps://api.staging.churchapps.org/giving
NEXT_PUBLIC_MESSAGING_APIMessaging API-URLhttps://api.staging.churchapps.org/messaging
NEXT_PUBLIC_CONTENT_APIContent API-URLhttps://api.staging.churchapps.org/content
NEXT_PUBLIC_CONTENT_ROOTURL for innholdsleveringhttps://staging.churchapps.org/content
NEXT_PUBLIC_CHURCH_APPS_URLChurchApps basis-URLhttps://staging.churchapps.org
NEXT_PUBLIC_GOOGLE_ANALYTICSGoogle Analytics-ID (valgfri)UA-123456789-1
Info

Next.js krever NEXT_PUBLIC_-prefikset for enhver miljøvariabel som må være tilgjengelig i nettleseren. Variabler som kun brukes på serveren trenger ikke dette prefikset.

LessonsApp (Next.js)

Eksempelfil: dotenv.sample.txt

VariabelBeskrivelseEksempel (staging)
STAGEMiljøstegstaging
NEXT_PUBLIC_LESSONS_APILessons API-URLhttps://api.staging.lessons.church
NEXT_PUBLIC_CONTENT_ROOTURL for innholdsleveringhttps://api.staging.lessons.church/content
NEXT_PUBLIC_CHURCH_APPS_URLChurchApps basis-URLhttps://staging.churchapps.org

Mobilapp-miljøvariabler

B1Mobile (React Native / Expo)

Eksempelfil: dotenv.sample.txt

VariabelBeskrivelseEksempel (staging)
STAGEMiljønavndev
MEMBERSHIP_APIMembership API-URLhttps://api.staging.churchapps.org/membership
MESSAGING_APIMessaging API-URLhttps://api.staging.churchapps.org/messaging
ATTENDANCE_APIAttendance API-URLhttps://api.staging.churchapps.org/attendance
GIVING_APIGiving API-URLhttps://api.staging.churchapps.org/giving
DOING_APIDoing API-URLhttps://api.staging.churchapps.org/doing
CONTENT_APIContent API-URLhttps://api.churchapps.org/content
CONTENT_ROOTURL for innholdsleveringhttps://content.staging.churchapps.org
LESSONS_ROOTLessons-nettsted-URLhttps://staging.lessons.church
Info

Mobilapper bruker ikke REACT_APP_- eller NEXT_PUBLIC_-prefikset. Tilgang til miljøvariabler håndteres av Expo-konfigurasjonen.


Hurtigreferanse: Eksempelfilplasseringer

ProsjektEksempelfil
Api.env.sample
B1Admin.env.sample
B1App.env.sample
B1Mobiledotenv.sample.txt
B1Checkindotenv.sample.txt
LessonsAppdotenv.sample.txt
AskApidotenv.sample.txt