Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,23 @@ services:
env_file:
- .env
restart: always
links:
- "db"
depends_on:
- db
db:
condition: service_healthy
db:
image: mongo:4.4
image: mongo:8.0
mem_limit: 512M
cpu_percent: 60
restart: always
command: ["mongod", "--replSet", "rs0", "--auth"]
environment:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: fworootpassword
volumes:
- db:/data/db
- db:/data/db
healthcheck:
test: |
mongosh --quiet --eval "try { rs.status().ok } catch(e) { 0 }" --authenticationDatabase admin -u root -p fworootpassword 2>/dev/null | grep -q 1
interval: 10s
retries: 30
start_period: 30s
13 changes: 6 additions & 7 deletions server/models/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import mongoose, { type ConnectOptions } from 'mongoose';

// MONGO - полный mongo uri:
// "mongodb://user:password@db:27017/fwo?retryWrites=true&w=majority&authSource=admin
// "mongodb://user:password@db:27017/fwo?retryWrites=true&w=majority&authSource=admin&replicaSet=rs0

mongoose.set('toObject', { virtuals: true });

Expand All @@ -16,19 +16,18 @@ export async function connect(onConnect?: () => void): Promise<void> {
switch (process.env.NODE_ENV) {
case 'production':
await mongoose.connect(
process.env.MONGO ?? 'mongodb://root:fworootpassword@db:27017/fwo',
process.env.MONGO ??
'mongodb://root:fworootpassword@db:27017/fwo?retryWrites=true&w=majority&authSource=admin&replicaSet=rs0',

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Не очень мне нравиться что мы храним эти прям в коде

options,
);
break;
case 'test':
await mongoose.connect(
process.env.MONGO ?? 'mongodb://localhost:27017/test-fwo',
options,
);
await mongoose.connect(process.env.MONGO ?? 'mongodb://localhost:27017/test-fwo', options);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dev и prod у тебя в rs, а вот тест почему то без

break;
case 'development':
await mongoose.connect(
process.env.MONGO ?? 'mongodb://root:fworootpassword@localhost:27017/fwo',
process.env.MONGO ??
'mongodb://root:fworootpassword@localhost:27017/fwo?retryWrites=true&w=majority&authSource=admin&replicaSet=rs0',
options,
);
break;
Expand Down
Loading