Replace bcrypt with bcryptjs / move env to config

This commit is contained in:
rui hildt 2020-05-07 15:10:15 +02:00
parent bf2fb47033
commit fce5a162d3
7 changed files with 30 additions and 10 deletions

View File

@ -1,7 +1,8 @@
require('dotenv').config();
const express = require('express');
const bodyParser = require('body-parser');
const cors = require('cors');
const helmet = require('helmet');
require('dotenv').config();
const accountsRoute = require('./routes/accountRoute');
const meetingsRoute = require('./routes/meetingRoute');
@ -15,6 +16,13 @@ server.use(cors());
server.use(express.json());
server.use(helmet());
server.use(bodyParser.json());
server.use(
bodyParser.urlencoded({
extended: true,
}),
);
server.use('/api/accounts', accountsRoute);
server.use('/api/meetings', meetingsRoute);
server.use('/api/participants', participantsRoute);

6
config/config.js Normal file
View File

@ -0,0 +1,6 @@
module.exports = {
jwt_secret: process.env.JWT_SECRET,
port: process.env.PORT || 3001,
db_url: process.env.DATABASE_URL,
environment: process.env.NODE_ENV,
};

View File

@ -1,8 +1,8 @@
const knex = require('knex');
const knexfile = require('../knexfile');
const { environment} = require('../config/config')
const env = process.env.NODE_ENV || 'development';
const env = environment || 'development';
const configOptions = knexfile[env];
module.exports = knex(configOptions);

View File

@ -1,9 +1,8 @@
const server = require('./api/server.js');
const { port } = require('./config/config');
const PORT = process.env.PORT || 3001;
server.listen(PORT, () =>
server.listen(port, () =>
console.log(
`Meeting Planner Backend listening at http://localhost:${PORT}`,
`Meeting Planner Backend listening at http://localhost:${port}`,
),
);

View File

@ -1,9 +1,10 @@
require('dotenv').config();
const { db_url } = require('./config/config');
module.exports = {
development: {
client: 'pg',
connection: process.env.DATABASE_URL,
connection: db_url,
migrations: {
directory: './data/migrations',
},
@ -13,7 +14,7 @@ module.exports = {
testing: {
client: 'pg',
connection: process.env.DATABASE_URL,
connection: db_url,
migrations: {
directory: './data/migrations',
},
@ -23,7 +24,7 @@ module.exports = {
production: {
client: 'pg',
connection: process.env.DATABASE_URL,
connection: db_url,
migrations: {
directory: './data/migrations',
},

5
package-lock.json generated
View File

@ -113,6 +113,11 @@
}
}
},
"bcryptjs": {
"version": "2.4.3",
"resolved": "https://registry.npmjs.org/bcryptjs/-/bcryptjs-2.4.3.tgz",
"integrity": "sha1-mrVie5PmBiH/fNrF2pczAn3x0Ms="
},
"bluebird": {
"version": "3.7.2",
"resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.7.2.tgz",

View File

@ -14,6 +14,7 @@
"author": "rui hildt",
"license": "AGPL-3.0-or-later",
"dependencies": {
"bcryptjs": "^2.4.3",
"cors": "^2.8.5",
"dotenv": "^8.2.0",
"express": "^4.17.1",