minimonolith 0.13.5 → 0.13.7

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 ADDED
@@ -0,0 +1,7 @@
1
+ MM_API_DB_DIALECT=mysql
2
+ MM_API_DB_HOST=0.0.0.0
3
+ MM_API_DB_USER=root
4
+ MM_API_DB_PASS=root
5
+ MM_API_DB_DB=todo
6
+ MM_API_PROD_ENV=false
7
+ MM_API_LOCAL_ENV=true
package/README.md CHANGED
@@ -131,3 +131,20 @@ export default (MODELS, ROUTE_CODE) => ({
131
131
  .superRefine(DB_VALIDATION.exists(MODELS.todo, 'id')),
132
132
  })
133
133
  ```
134
+
135
+ ## Database Authentication
136
+
137
+ To set up authentication for the database, you need to provide the necessary environment variables in a `.env` file. Here's an example of a `.env` file for connecting to a MySQL database at 0.0.0.0:
138
+
139
+ ```makefile
140
+ MM_API_DB_USERNAME=<your_database_username>
141
+ MM_API_DB_PASSWORD=<your_database_password>
142
+ MM_API_DB_DATABASE=<your_database_name>
143
+ MM_API_DB_HOST=0.0.0.0
144
+ MM_API_DB_PORT=<your_database_port>
145
+ MM_API_DB_DIALECT=mysql
146
+ MM_API_LOCAL_ENV=true
147
+ MM_API_PROD_ENV=false
148
+ ```
149
+
150
+ Make sure to replace the placeholders with your actual database credentials. The `MM_API_LOCAL_ENV` variable is used to allow Sequelize to alter table structure automatically when working locally, while the `MM_API_PROD_ENV` variable controls logging of secret credentials for debugging purposes in non-production environments.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "minimonolith",
3
3
  "type": "module",
4
- "version": "0.13.5",
4
+ "version": "0.13.7",
5
5
  "main": "index.js",
6
6
  "license": "MIT",
7
7
  "scripts": {
@@ -27,11 +27,12 @@ const establishConnection = async ORM => {
27
27
 
28
28
  const registerDatabaseService = async API => {
29
29
  try {
30
- const { DB_DIALECT, DB_DB, DB_USER, DB_PASS, DB_HOST } = process.env;
31
- const SEQUELIZE_OPTIONS = { host: DB_HOST, dialect: DB_DIALECT, logging: false };
30
+ const { MM_API_DB_DIALECT, MM_API_DB_DB, MM_API_DB_USER, MM_API_DB_PASS, MM_API_DB_HOST } = process.env;
31
+ const SEQUELIZE_OPTIONS = { host: MM_API_DB_HOST, dialect: MM_API_DB_DIALECT, logging: false };
32
32
 
33
- if (!process.env.PROD_ENV) console.log({ ROUTE_CODE, DB_VARS: { DB_USER, DB_PASS, DB_HOST, DB_DB, }});
34
- API.ORM = new Sequelize(DB_DB, DB_USER, DB_PASS, SEQUELIZE_OPTIONS);
33
+ if (!process.env.PROD_ENV) console.log({ ROUTE_CODE,
34
+ MM_API_DB_VARS: { MM_API_DB_USER, MM_API_DB_PASS, MM_API_DB_HOST, MM_API_DB_DB, }});
35
+ API.ORM = new Sequelize(MM_API_DB_DB, MM_API_DB_USER, MM_API_DB_PASS, SEQUELIZE_OPTIONS);
35
36
  establishConnection(API.ORM);
36
37
 
37
38
  } catch (DB_ERROR) { console.error({ ROUTE_CODE, DB_ERROR }); }
@@ -45,7 +45,7 @@ const getServerHandler = lambdaHandler => async (req, res) => {
45
45
  if (req.method === 'OPTIONS') { res.writeHead(200); res.end(); return; }
46
46
 
47
47
  const authHeader = req.headers.authorization;
48
- const jwtClaims = authHeader?.startsWith('Bearer ') ? getJWTClaim(authHeader) : null;
48
+ const jwtClaims = authHeader?.startsWith('Bearer ') ? getJWTClaims(authHeader) : null;
49
49
 
50
50
  const tempQueryString = url.parse(req.url, true).query;
51
51
  const queryString = tempQueryString ? tempQueryString : undefined;
@@ -19,7 +19,7 @@ const loadAndSyncModels = async API => {
19
19
  Object.entries(MODELS).forEach(([serviceName, model]) => { model.associate(MODELS); });
20
20
 
21
21
  console.log({ ROUTE_CODE, SYNCING_ORM: 'SYNCING_ORM' });
22
- await API.ORM.sync({ alter: process.env.LOCAL_ENV ? true : false });
22
+ await API.ORM.sync({ alter: process.env.MM_API_LOCAL_ENV ? true : false });
23
23
 
24
24
  return MODELS;
25
25
  };