minimonolith 0.23.0 → 0.23.2

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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # minimonolith
2
2
 
3
- [![codecov](https://codecov.io/gh/DeepHackDev/minimonolith-lib/branch/master/graph/badge.svg?token=ORFNKKJRSE)](https://codecov.io/gh/DeepHackDev/minimonolith-lib)
3
+ [![codecov](https://codecov.io/gh/DeepHackDev/minimonolith-api/branch/master/graph/badge.svg?token=ORFNKKJRSE)](https://codecov.io/gh/DeepHackDev/minimonolith-lib)
4
4
 
5
5
  `minimonolith` is a lightweight library designed to help you build serverless APIs using AWS Lambda, with a focus on simplicity and ease of use. The library provides a straightforward structure to organize your API's services, methods, validation, and models while handling common tasks like database connection and request validation.
6
6
 
@@ -63,7 +63,6 @@ await API.postDatabaseService({
63
63
  DB_DB: process.env.DB_DB,
64
64
  DB_USER: process.env.DB_USER,
65
65
  DB_PASS: process.env.DB_PASS,
66
- DB_STORAGE: process.env.DB_STORAGE,
67
66
  });
68
67
 
69
68
  export const lambdaHandler = await API.getSyncedHandler();
@@ -175,7 +174,7 @@ TEST_ENV=FALSE
175
174
  ## Database Authentication
176
175
 
177
176
  To set up authentication for the database you need to pass necessary variables to postDatabaseService as at index.js above.
178
- Assuming using same env variables as used at index.js above
177
+ Assuming using same env variable names as at index.js above
179
178
 
180
179
  For MySQL:
181
180
 
@@ -190,16 +189,14 @@ DB_USER=<your_database_username>
190
189
  DB_PASS=<your_database_password>
191
190
  ```
192
191
 
193
- For SQLite:
192
+ For SQLite in memory:
194
193
 
195
194
  ```makefile
196
195
  DEV_ENV=TRUE
197
196
  PROD_ENV=FALSE
198
197
  DB_DIALECT=sqlite
199
198
  DB_DB=<your_database_name>
200
- DB_STORAGE=:memory: # For in-memory SQLite database
201
- # Or
202
- DB_STORAGE=path/to/your/sqlite/file.db # For file-based SQLite database
199
+ DB_STORAGE=:memory: # Need to also pass to API.postDatabaseService()
203
200
  ```
204
201
 
205
202
  Make sure to replace the placeholders with your actual database credentials.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "minimonolith",
3
3
  "type": "module",
4
- "version": "0.23.0",
4
+ "version": "0.23.2",
5
5
  "main": "index.js",
6
6
  "license": "MIT",
7
7
  "scripts": {
@@ -28,5 +28,6 @@ export default async (SERVICE_NAME, SRC_FOLDER='', MODULES_FOLDER='node_modules/
28
28
  for (const METHOD_CODE of SERVICE_MODULE.default) await METHOD_SERVICE.post(SERVICE_NAME, SERVICE_URL, METHOD_CODE);
29
29
 
30
30
  } catch (META_METHOD_ERROR) {
31
- ERROR_SERVICE.postCompiletime({ META_SERVICE_NAME, META_METHOD_NAME, META_METHOD_ERROR }); }
31
+ ERROR_SERVICE.postCompiletime({ META_SERVICE_NAME, META_METHOD_NAME, META_METHOD_ERROR });
32
+ }
32
33
  };
@@ -0,0 +1,6 @@
1
+ export default {
2
+ 'Access-Control-Allow-Origin': '*',
3
+ 'Access-Control-Allow-Methods': 'OPTIONS, POST, GET, PUT, PATCH, DELETE',
4
+ 'Access-Control-Allow-Headers': '*',
5
+ 'Access-Control-Allow-Credentials': true,
6
+ };
@@ -1,6 +1,8 @@
1
1
  import API_SERVICE from '../../api/index.js';
2
2
  import LOG_SERVICE from '../../log/index.js';
3
3
 
4
+ import CORS_HEADERS from './corsHeaders.js';
5
+
4
6
  export default () => {
5
7
 
6
8
  API_SERVICE.get().use((req, res, next) => {
@@ -12,10 +14,7 @@ export default () => {
12
14
  });
13
15
 
14
16
  API_SERVICE.get().options('/*', (req, res) => {
15
- res.header('Access-Control-Allow-Origin', '*');
16
- res.header('Access-Control-Allow-Methods', 'OPTIONS, POST, GET, PUT, PATCH, DELETE');
17
- res.header('Access-Control-Allow-Headers', '*');
18
- res.header('Access-Control-Allow-Credentials', true);
17
+ for (let k in CORS_HEADERS) { res.header(k, CORS_HEADERS[k]); }
19
18
  res.status(200).send({})
20
19
  });
21
20
  };
@@ -4,6 +4,8 @@ import url from 'url';
4
4
 
5
5
  import LOG_SERVICE from '../../log/index.js';
6
6
 
7
+ import CORS_HEADERS from '../../middleware/postCors/corsHeaders.js';
8
+
7
9
  const getBody = req => {
8
10
  return new Promise((resolve, reject) => {
9
11
  let body = '';
@@ -54,11 +56,13 @@ export default lambdaHandler => async (req, res) => {
54
56
  const lambdaRes = await lambdaHandler(lambdaEvent, null)
55
57
 
56
58
  res.statusCode = lambdaRes.statusCode;
59
+ for (let k in CORS_HEADERS) res.setHeader(k, CORS_HEADERS[k]);
57
60
  res.end(lambdaRes.body);
58
61
 
59
62
  } catch(SERVER_ERROR) {
60
63
  LOG_SERVICE.post({ SERVER_ERROR });
61
64
  res.statusCode = 500;
65
+ for (let k in CORS_HEADERS) res.setHeader(k, CORS_HEADERS[k]);
62
66
  res.end(JSON.stringify({ REQUEST_PARSING_ERROR: SERVER_ERROR.toString() }));
63
67
  }
64
68
  }
package/.env.example DELETED
@@ -1,4 +0,0 @@
1
- MM_API_DB_DIALECT=sqlite
2
- MM_API_DB_STORAGE=:memory:
3
- MM_API_PROD_ENV=FALSE
4
- MM_API_DEV_ENV=TRUE