Skip to content

Commit

Permalink
feat(agora): change agora-api to construct mongo URI from host, usern…
Browse files Browse the repository at this point in the history
…ame, password, port, and DB name env variables (AG-1592) (#2967)
  • Loading branch information
hallieswan authored Jan 16, 2025
1 parent c02e5df commit 7fbf496
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 7 deletions.
6 changes: 5 additions & 1 deletion apps/agora/api/.env.example
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
MONGODB_URI="mongodb://root:changeme@agora-mongo:27017/agora?authSource=admin"
MONGODB_PASS="changeme"
MONGODB_USER="root"
MONGODB_HOST="agora-mongo"
MONGODB_PORT="27017"
MONGODB_NAME="agora"
NODE_ENV="development"
32 changes: 29 additions & 3 deletions apps/agora/api/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,39 @@ import {
teamsRoute,
} from './components';

const mongoUri = process.env.MONGODB_URI;
const mongodbUser = process.env.MONGODB_USER;
const mongodbPass = process.env.MONGODB_PASS;
const mongodbHost = process.env.MONGODB_HOST;
const mongodbPort = process.env.MONGODB_PORT;
const mongodbName = process.env.MONGODB_NAME;

if (!mongoUri) {
console.error('No MONGODB_URI environment variable has been defined.');
if (!mongodbUser) {
console.error('No MONGODB_USER environment variable has been defined.');
process.exit(1);
}

if (!mongodbPass) {
console.error('No MONGODB_PASS environment variable has been defined.');
process.exit(1);
}

if (!mongodbHost) {
console.error('No MONGODB_HOST environment variable has been defined.');
process.exit(1);
}

if (!mongodbPort) {
console.error('No MONGODB_PORT environment variable has been defined.');
process.exit(1);
}

if (!mongodbName) {
console.error('No MONGODB_NAME environment variable has been defined.');
process.exit(1);
}

const mongoUri = `mongodb://${mongodbUser}:${mongodbPass}@${mongodbHost}:${mongodbPort}/${mongodbName}?authSource=admin`;

mongoose
.connect(mongoUri)
.then(() => console.log('Connected to MongoDB'))
Expand Down
4 changes: 3 additions & 1 deletion apps/agora/app/.env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
API_DOCS_URL="http://localhost:8000/api-docs"
APP_VERSION="4.0.0"
CSR_API_URL="http://localhost:8000/api/v1"
SSR_API_URL="http://agora-api:3333/v1"
SSR_API_URL="http://agora-api:3333/v1"
ROLLBAR_TOKEN="e788198867474855a996485580b08d03"
TAG_NAME="agora/v4.0.0-rc1"
2 changes: 1 addition & 1 deletion apps/agora/app/src/config/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
"csrApiUrl": "http://localhost:3333/v1",
"ssrApiUrl": "http://agora-api:3333/v1",
"rollbarToken": "e788198867474855a996485580b08d03",
"tagName": "agora/v0.0.2"
"tagName": "agora/v4.0.0-rc1"
}
2 changes: 1 addition & 1 deletion docker/agora/services/apex.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ services:
ports:
- '8000:80'
healthcheck:
test: ['CMD', 'curl', '--fail', 'http://localhost:80/health']
test: ['CMD', 'wget', '--spider', '--quiet', 'http://localhost:80/health']
interval: 30s
timeout: 10s
retries: 3
Expand Down

0 comments on commit 7fbf496

Please sign in to comment.