Skip to content

Commit

Permalink
feat: Improve configs storing
Browse files Browse the repository at this point in the history
  • Loading branch information
letehaha committed Jul 16, 2023
1 parent dfa292a commit b6f9482
Show file tree
Hide file tree
Showing 16 changed files with 60 additions and 76 deletions.
11 changes: 11 additions & 0 deletions .env.template
Original file line number Diff line number Diff line change
@@ -1,2 +1,13 @@
# used in migrations to fetch actual currencies rates
API_LAYER_API_KEY=

APPLICATION_HOST=
APPLICATION_PORT=
APPLICATION_JWT_SECRET=
APPLICATION_DB_HOST=
APPLICATION_DB_USERNAME=
APPLICATION_DB_PASSWORD=
APPLICATION_DB_DATABASE=
APPLICATION_DB_PORT=
APPLICATION_DB_DIALECT=
APPLICATION_REDIS_HOST=
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
src/seeders/**/*.js
src/migrations/**/*.js
.eslintrc.js
config/db/config.js
config/**
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ typings/
# dotenv environment variables file
.env
.env.test
.env.development
.env.production

# parcel-bundler cache (https://parceljs.org/)
.cache
Expand Down
2 changes: 1 addition & 1 deletion .sequelizerc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const path = require('path');
require('dotenv').config();
require('dotenv').config({ path: `.env.${process.env.NODE_ENV}` })

module.exports = {
"config": path.resolve('./config/db', 'config.js'),
Expand Down
1 change: 1 addition & 0 deletions config/db/config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require('dotenv').config({ path: `.env.${process.env.NODE_ENV}` });
const config = require('config').get('db');

const options = {
Expand Down
26 changes: 26 additions & 0 deletions config/default.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Default file that being merged with others env-related files

module.exports = {
name: 'budget-tracker-be',
host: process.env.APPLICATION_HOST,
port: process.env.APPLICATION_PORT,
apiPrefix: '/api/v1',
jwtSecret: process.env.APPLICATION_JWT_SECRET,
db: {
host: process.env.APPLICATION_DB_HOST,
username: process.env.APPLICATION_DB_USERNAME,
password: process.env.APPLICATION_DB_PASSWORD,
database: process.env.APPLICATION_DB_DATABASE,
port: process.env.APPLICATION_DB_PORT,
dialect: process.env.APPLICATION_DB_DIALECT,
logging: true,
},
redis: {
host: process.env.APPLICATION_REDIS_HOST,
},
bankIntegrations: {
monobank: {
apiEndpoint: 'https://api.monobank.ua'
}
},
}
8 changes: 0 additions & 8 deletions config/default.json

This file was deleted.

5 changes: 5 additions & 0 deletions config/development.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
env: 'development',
envShort: 'dev',
hostWebhooksCallback: 'http://d8d75e719def.ngrok.io',
}
21 changes: 0 additions & 21 deletions config/development.json

This file was deleted.

5 changes: 5 additions & 0 deletions config/production.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
env: 'production',
envShort: 'prod',
hostWebhooksCallback: 'http://d8d75e719def.ngrok.io',
}
21 changes: 0 additions & 21 deletions config/production.json

This file was deleted.

5 changes: 5 additions & 0 deletions config/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
env: 'test',
envShort: 'test',
hostWebhooksCallback: 'http://d8d75e719def.ngrok.io',
}
21 changes: 0 additions & 21 deletions config/test.json

This file was deleted.

2 changes: 1 addition & 1 deletion jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
export default {
preset: 'ts-jest',
testEnvironment: 'node',
testMatch: ['**/?(*.)+(spec|test|e2e).[jt]s?(x)'],
testMatch: ['**/?(*.)+(unit|spec|e2e).[jt]s?(x)'],
globals: {
'ts-jest': {
tsconfig: 'tsconfig.json',
Expand Down
2 changes: 1 addition & 1 deletion src/app.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import dotenv from "dotenv";
import 'module-alias/register';

dotenv.config();
dotenv.config({ path: `.env.${process.env.NODE_ENV}` });
import config from 'config';
import express, { Request } from 'express';
import cors from 'cors';
Expand Down
2 changes: 1 addition & 1 deletion src/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const sequelize = new Sequelize({
models: [__dirname + '/**/*.model.ts'],
});

if (process.env.NODE_ENV === 'development') {
if (['development', 'test'].includes(process.env.NODE_ENV)) {
console.log('DBConfig', DBConfig);
}

Expand Down

0 comments on commit b6f9482

Please sign in to comment.