Skip to content

Commit 0899413

Browse files
authored
Merge pull request #13 from which-ecosystem/deployment
Setup project for Heroku deployment
2 parents c4619eb + 1fbf5ff commit 0899413

File tree

4 files changed

+83
-14
lines changed

4 files changed

+83
-14
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

package-lock.json

Lines changed: 52 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"version": "1.0.0",
44
"main": "index.ts",
55
"scripts": {
6+
"start": "ts-node index.ts",
67
"lint": "eslint . --ext ts --max-warnings 0",
78
"test": "npm run lint"
89
},
@@ -18,11 +19,19 @@
1819
"@feathersjs/feathers": "^4.5.3",
1920
"@feathersjs/socketio": "^4.5.4",
2021
"@feathersjs/transport-commons": "^4.5.3",
22+
"@types/bluebird": "^3.5.32",
23+
"@types/cors": "^2.8.6",
24+
"@types/lodash": "^4.14.155",
25+
"@types/mongoose": "^5.7.23",
26+
"@typescript-eslint/eslint-plugin": "^3.2.0",
27+
"@typescript-eslint/parser": "^3.2.0",
2128
"bluebird": "^3.7.2",
2229
"cors": "^2.8.5",
2330
"feathers-mongoose": "^8.3.0",
2431
"lodash": "^4.17.15",
2532
"mongoose": "^5.9.18",
33+
"ts-node": "^8.10.2",
34+
"typescript": "^3.9.5",
2635
"which-types": "^1.4.1"
2736
},
2837
"repository": {
@@ -35,15 +44,8 @@
3544
"homepage": "https://github.com/eug-vs/which-api#readme",
3645
"description": "",
3746
"devDependencies": {
38-
"@types/bluebird": "^3.5.32",
39-
"@types/cors": "^2.8.6",
40-
"@types/lodash": "^4.14.155",
41-
"@types/mongoose": "^5.7.23",
42-
"@typescript-eslint/eslint-plugin": "^3.2.0",
43-
"@typescript-eslint/parser": "^3.2.0",
4447
"eslint": "^7.2.0",
4548
"eslint-config-airbnb-typescript": "^8.0.2",
46-
"eslint-plugin-import": "^2.21.2",
47-
"typescript": "^3.9.5"
49+
"eslint-plugin-import": "^2.21.2"
4850
}
4951
}

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)