Skip to content

Commit 1fbf5ff

Browse files
committed
build: conntect to database correctly
1 parent 4a3be03 commit 1fbf5ff

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

index.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,17 @@ import app from './app';
44

55
mongoose.Promise = Promise;
66

7-
mongoose.connect('mongodb://localhost:27017/which', { useNewUrlParser: true });
7+
8+
const MONGODB_URL = process.env.MONGODB_URI || 'mongodb://localhost:27017/which';
9+
const PORT = process.env.PORT || 3030;
10+
11+
mongoose.connect(MONGODB_URL, {
12+
useNewUrlParser: true,
13+
useUnifiedTopology: true,
14+
useCreateIndex: true,
15+
useFindAndModify: false,
16+
family: 4 // Use IPv4, skip trying IPv6
17+
});
818

919
const db = mongoose.connection;
1020
db.on('error', console.error.bind(console, 'connection error:'));
@@ -18,6 +28,5 @@ app.on('connection', connection => app.channel('everybody').join(connection));
1828
app.publish(() => app.channel('everybody'));
1929

2030

21-
const port = 3030;
22-
app.listen(port).on('listening', () => console.log(`Feathers server listening on localhost:${port}`));
31+
app.listen(PORT).on('listening', () => console.log(`Feathers server listening on localhost:${PORT}`));
2332

populateDb.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,15 @@ import { User, Poll, Vote } from 'which-types';
55

66
import app from './app';
77

8-
mongoose.connect('mongodb://localhost:27017/which', { useNewUrlParser: true });
8+
const MONGODB_URL = process.env.MONGODB_URI || 'mongodb://localhost:27017/which';
9+
10+
mongoose.connect(MONGODB_URL, {
11+
useNewUrlParser: true,
12+
useUnifiedTopology: true,
13+
useCreateIndex: true,
14+
useFindAndModify: false,
15+
family: 4 // Use IPv4, skip trying IPv6
16+
});
917

1018
const POLLS_AMOUNT = 20;
1119

0 commit comments

Comments
 (0)