minimonolith 0.18.1 → 0.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env.example +2 -2
- package/README.md +34 -6
- package/package.json +1 -1
- package/src/crasher/crasher.js +1 -1
- package/src/database/databaseService.js +1 -1
- package/src/logger/logger.js +1 -1
- package/src/model/loadModels.js +1 -1
package/.env.example
CHANGED
package/README.md
CHANGED
|
@@ -114,6 +114,29 @@ export default ({ MODELS }) => ({
|
|
|
114
114
|
})
|
|
115
115
|
```
|
|
116
116
|
|
|
117
|
+
## App Environments
|
|
118
|
+
|
|
119
|
+
There are 4 possible environments: DEV=TRUE & PROD=FALSE, DEV=TRUE & PROD=TRUE, DEV=FALSE & PROD=TRUE, DEV=FALSE & PROD=TRUE
|
|
120
|
+
1. DEV=TRUE & PROD=FALSE: This is the standard DEV environment
|
|
121
|
+
2. DEV=FALSE & PROD=FALSE: This is the standard QA environment
|
|
122
|
+
3. DEV=FALSE & PROD=TRUE: This is the stnadard PROD environment
|
|
123
|
+
4. DEV=TRUE & PROD=TRUE: This allows to test the behavior of PROD within the "new concept" of DEV environment
|
|
124
|
+
|
|
125
|
+
To better understand their relevance:
|
|
126
|
+
1. The "new concept" DEV environments (DEV=TRUE) aim to make the api crash if an "important" error happens
|
|
127
|
+
1. Its current only difference is it makes it crash on error at service registration phase
|
|
128
|
+
2. The "new concept" QA environments (PROD=FALSE) aim at logging data about the system which on production environments would be forbiden personal information
|
|
129
|
+
1. This is relevant because replication of QA activities (even security QA activities) depend heavily on this
|
|
130
|
+
|
|
131
|
+
The current App environment is determined on the values of MM_API_DEV ENV [TRUE/FALSE] and MM_API_PROD_ENV [TRUE/FALSE]:
|
|
132
|
+
|
|
133
|
+
```makefile
|
|
134
|
+
# .env standard dev environment
|
|
135
|
+
MM_API_DEV_ENV=TRUE
|
|
136
|
+
MM_API_PROD_ENV=FALSE
|
|
137
|
+
[...]
|
|
138
|
+
```
|
|
139
|
+
|
|
117
140
|
## Database Authentication
|
|
118
141
|
|
|
119
142
|
To set up authentication for the database, you need to provide the necessary environment variables in a `.env` file. Depending on the database dialect the required variables will differ.
|
|
@@ -121,27 +144,32 @@ To set up authentication for the database, you need to provide the necessary env
|
|
|
121
144
|
For MySQL:
|
|
122
145
|
|
|
123
146
|
```makefile
|
|
147
|
+
MM_API_DEV_ENV=TRUE
|
|
148
|
+
MM_API_PROD_ENV=FALSE
|
|
124
149
|
MM_API_DB_DIALECT=mysql
|
|
125
150
|
MM_API_DB_HOST=<your_database_endpoint>
|
|
126
151
|
MM_API_DB_PORT=<your_database_port>
|
|
127
152
|
MM_API_DB_DATABASE=<your_database_name>
|
|
128
153
|
MM_API_DB_USERNAME=<your_database_username>
|
|
129
154
|
MM_API_DB_PASSWORD=<your_database_password>
|
|
130
|
-
MM_API_LOCAL_ENV=true
|
|
131
|
-
MM_API_PROD_ENV=false
|
|
132
155
|
```
|
|
133
156
|
|
|
134
157
|
For SQLite:
|
|
135
158
|
|
|
136
159
|
```makefile
|
|
160
|
+
MM_API_DEV_ENV=TRUE
|
|
161
|
+
MM_API_PROD_ENV=FALSE
|
|
137
162
|
MM_API_DB_DIALECT=sqlite
|
|
138
163
|
MM_API_DB_STORAGE=:memory: # For in-memory SQLite database
|
|
139
164
|
# Or
|
|
140
165
|
MM_API_DB_STORAGE=path/to/your/sqlite/file.db # For file-based SQLite database
|
|
141
166
|
MM_API_DB_DATABASE=<your_database_name>
|
|
142
|
-
MM_API_LOCAL_ENV=true
|
|
143
|
-
MM_API_PROD_ENV=false
|
|
144
167
|
```
|
|
145
168
|
|
|
146
|
-
Make sure to replace the placeholders with your actual database credentials.
|
|
147
|
-
|
|
169
|
+
Make sure to replace the placeholders with your actual database credentials.
|
|
170
|
+
- `MM_API_DEV_ENV=TRUE` allows Sequelize to alter table structure automatically when working locally
|
|
171
|
+
- `MM_API_PROD_ENV=FALSE` allows logging of DB credentials for debugging purposes in non-production environments
|
|
172
|
+
- We consider high quality logging important for app performance and evolution
|
|
173
|
+
- However we recommend automatic DB credentials updates (daily) High quality logging does not mean
|
|
174
|
+
giving away your infraestructure to hackers
|
|
175
|
+
- At the risk of stating the obvious do not store personal information at the QA database
|
package/package.json
CHANGED
package/src/crasher/crasher.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default ERROR => { if (process.env.
|
|
1
|
+
export default ERROR => { if (process.env.MM_API_DEV_ENV==='TRUE') throw ERROR; };
|
|
@@ -35,7 +35,7 @@ const registerDatabaseService = async API => {
|
|
|
35
35
|
const SEQUELIZE_OPTIONS = { dialect: MM_API_DB_DIALECT, host: MM_API_DB_HOST,
|
|
36
36
|
port: MM_API_DB_PORT, storage: MM_API_DB_STORAGE, logging: false };
|
|
37
37
|
|
|
38
|
-
logger.
|
|
38
|
+
logger.qa({ ROUTE_CODE, MM_API_DB_VARS: { MM_API_DB_DIALECT,
|
|
39
39
|
MM_API_DB_USER, MM_API_DB_PASS, MM_API_DB_HOST, MM_API_DB_PORT, MM_API_DB_DB, MM_API_DB_STORAGE }});
|
|
40
40
|
API.ORM = new Sequelize(MM_API_DB_DB, MM_API_DB_USER, MM_API_DB_PASS, SEQUELIZE_OPTIONS);
|
|
41
41
|
establishConnection(API.ORM);
|
package/src/logger/logger.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export default {
|
|
2
2
|
error: (...ERROR) => { console.error(...ERROR) },
|
|
3
3
|
log: (...MESSAGE) => { console.log(...MESSAGE) },
|
|
4
|
-
|
|
4
|
+
qa: (...MESSAGE) => { if (process.env.MM_API_PROD_ENV!=='TRUE') console.log(...MESSAGE) }
|
|
5
5
|
};
|
package/src/model/loadModels.js
CHANGED
|
@@ -24,7 +24,7 @@ const loadAndSyncModels = async API => {
|
|
|
24
24
|
});
|
|
25
25
|
|
|
26
26
|
logger.log({ ROUTE_CODE, SYNCING_ORM: 'WAITING_FOR_ORM_SYNCING' });
|
|
27
|
-
await API.ORM.sync({ alter: process.env.
|
|
27
|
+
await API.ORM.sync({ alter: process.env.MM_API_DEV_ENV==='TRUE' ? true : false });
|
|
28
28
|
logger.log({ ROUTE_CODE, SYNCING_ORM: 'DONE_ORM_SYNCING' });
|
|
29
29
|
|
|
30
30
|
return MODELS;
|