Skip to content

Commit

Permalink
.env variables
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiobarboza7 committed Jul 26, 2019
1 parent cd7a601 commit 5ea3764
Show file tree
Hide file tree
Showing 14 changed files with 70 additions and 19 deletions.
33 changes: 33 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
APP_URL=http://localhost:3333
NODE_ENV=development

# Auth

APP_SECRET=bootcampgobarbernode

# Database

DB_HOST=
DB_USER=
DB_PASS=
DB_NAME=

# Mongo

MONGO_URL=

# Redis

REDIS_HOST=127.0.0.1
REDIS_POST=6379

# Mail

MAIL_HOST=
MAIL_PORT=
MAIL_USER=
MAIL_PASS=

# Sentry

SENTRY_DSN=
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
.env
2 changes: 2 additions & 0 deletions node_modules/.yarn-integrity

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"bcryptjs": "^2.4.3",
"bee-queue": "^1.2.2",
"date-fns": "^2.0.0-beta.3",
"dotenv": "^8.0.0",
"express": "^4.17.1",
"express-async-errors": "^3.1.1",
"express-handlebars": "^3.1.0",
Expand Down
9 changes: 7 additions & 2 deletions src/app.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'dotenv/config';
import express from 'express';
import path from 'path';
import Youch from 'youch';
Expand Down Expand Up @@ -34,9 +35,13 @@ class App {

exceptionHandler() {
this.server.use(async (err, req, res, next) => {
const errors = await new Youch(err, req).toJSON();
if (process.env.NODE_ENV === 'development') {
const errors = await new Youch(err, req).toJSON();

return res.status(500).json(errors);
return res.status(500).json(errors);
}

return res.status(500).json({ error: 'Internal server error' });
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/models/File.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class File extends Model {
url: {
type: Sequelize.VIRTUAL,
get() {
return `http://localhost:3333/files/${this.path}`;
return `${process.env.APP_URL}/files/${this.path}`;
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion src/config/auth.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default {
secret: '519b5358c603267e6a1702a68a3b749b',
secret: process.env.APP_SECRET,
expiresIn: '7d',
};
10 changes: 6 additions & 4 deletions src/config/database.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
require('dotenv/config');

module.exports = {
dialect: 'postgres',
host: 'localhost',
username: 'postgres',
password: 'docker',
database: 'gobarber',
host: process.env.DB_HOST,
username: process.env.DB_USER,
password: process.env.DB_PASS,
database: process.env.DB_NAME,
port: 5434,
define: {
timestamps: true,
Expand Down
8 changes: 4 additions & 4 deletions src/config/mail.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
export default {
host: 'smtp.mailtrap.io',
port: 2525,
host: process.env.MAIL_HOST,
port: process.env.MAIL_PORT,
secure: false,
auth: {
user: 'bf68c0c53c2c39',
pass: '05233a5d03725b',
user: process.env.MAIL_USER,
pass: process.env.MAIL_PASS,
},
default: {
from: 'Equipe GoBarber <[email protected]>',
Expand Down
4 changes: 2 additions & 2 deletions src/config/redis.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default {
host: '127.0.0.1',
port: 6379,
host: process.env.REDIS_HOST,
port: process.env.REDIS_PORT,
};
2 changes: 1 addition & 1 deletion src/config/sentry.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export default {
dsn: 'https://[email protected]/1514707',
dsn: process.env.SENTRY_DSN,
};
8 changes: 4 additions & 4 deletions src/database/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ class Database {
}

mongo() {
this.mongoConnection = mongoose.connect(
'mongodb://localhost:27017/gobarber',
{ useNewUrlParser: true, useFindAndModify: true }
);
this.mongoConnection = mongoose.connect(process.env.MONGO_URL, {
useNewUrlParser: true,
useFindAndModify: true,
});
}
}

Expand Down
1 change: 1 addition & 0 deletions src/queue.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'dotenv/config';
import Queue from './lib/Queue';

Queue.processQueue();
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,11 @@ dot-prop@^4.1.0:
dependencies:
is-obj "^1.0.0"

dotenv@^8.0.0:
version "8.0.0"
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-8.0.0.tgz#ed310c165b4e8a97bb745b0a9d99c31bda566440"
integrity sha512-30xVGqjLjiUOArT4+M5q9sYdvuR4riM6yK9wMcas9Vbp6zZa+ocC9dp6QoftuhTPhFAiLK/0C5Ni2nou/Bk8lg==

dottie@^2.0.0:
version "2.0.1"
resolved "https://registry.yarnpkg.com/dottie/-/dottie-2.0.1.tgz#697ad9d72004db7574d21f892466a3c285893659"
Expand Down

0 comments on commit 5ea3764

Please sign in to comment.