Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set mongoDBUrl as a node env var #73

Merged
merged 2 commits into from Oct 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Expand Up @@ -2,7 +2,6 @@ node_modules
dist
coverage
cypress/screenshots
secrets/prod

debug.log

Expand Down
4 changes: 3 additions & 1 deletion README.md
Expand Up @@ -88,7 +88,9 @@ npm run ftest-ui

### Prod Environment

1. Set `secrets/prod/mongDBUrl` file with your DB url
1. Set `MONGODB_URL` environment variable in your node environment with your DB url.

In Heroku, that can be done using `Config Vars`.

2. Install dependencies

Expand Down
4 changes: 2 additions & 2 deletions package.json
@@ -1,11 +1,11 @@
{
"name": "cooking-with-amateurs",
"version": "1.1.4",
"version": "1.1.5",
"description": "Portfolio Web App about Cooking Recipes",
"main": "src/index.js",
"scripts": {
"dev-front": "webpack-dev-server --config webpack/webpack.dev.js",
"dev-back": "set NODE_ENV=development&& nodemon server/main.js",
"dev-back": "NODE_ENV=development MONGODB_URL=mongodb://localhost/Tododb nodemon server/main.js",
"utest": "jest src && jest cypress/utils",
"utest-cover": "jest src --coverage && jest cypress/utils --coverage",
"ftest": "cypress run",
Expand Down
1 change: 0 additions & 1 deletion secrets/dev/mongoDBUrl

This file was deleted.

2 changes: 1 addition & 1 deletion server/main.js
Expand Up @@ -5,7 +5,7 @@ const PORT = process.env.PORT || 5000;
const PRODUCTION_ENV = 'production';
const isProdEnv = process.env.NODE_ENV === PRODUCTION_ENV;

mongoDB.init(isProdEnv);
mongoDB.init(process.env.MONGODB_URL);
app.init(PORT, isProdEnv);

console.log(`RESTful API server started on: ${PORT}`);
6 changes: 1 addition & 5 deletions server/mongoDB.js
@@ -1,12 +1,8 @@
const fs = require('fs');
const mongoose = require('mongoose');

const recipeModel = require('./api/models/recipe-model');

exports.init = isProdEnv => {
const SECRETS_PATH = `secrets/${isProdEnv ? 'prod' : 'dev'}/mongoDBUrl`;
const mongoDBUrl = fs.readFileSync(SECRETS_PATH, 'utf-8');

exports.init = mongoDBUrl => {
mongoose.Promise = global.Promise;

mongoose.connect(mongoDBUrl, () => {
Expand Down