minimonolith 0.23.1 → 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
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "minimonolith",
3
3
  "type": "module",
4
- "version": "0.23.1",
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
  }