redweb 0.4.8 → 0.4.9
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/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const express = require('express');
|
|
2
2
|
const bodyParser = require('body-parser');
|
|
3
3
|
const path = require('path');
|
|
4
|
+
const cors = require('cors');
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* @typedef {'json' | 'urlencoded'} RedWebEncoding
|
|
@@ -19,6 +20,7 @@ const path = require('path');
|
|
|
19
20
|
* @property {string} [ssl.key] - Path to the SSL key file.
|
|
20
21
|
* @property {string} [ssl.cert] - Path to the SSL certificate file.
|
|
21
22
|
* @property {import('express').Application} [server] - Whether to automatically start listening.
|
|
23
|
+
* @property {import('cors').CorsOptions} [corsOptions] - The CORS Options.
|
|
22
24
|
*/
|
|
23
25
|
|
|
24
26
|
const ENCODINGS = { json: 'json', urlencoded: 'urlencoded' };
|
|
@@ -30,7 +32,8 @@ const HTTP_OPTIONS = {
|
|
|
30
32
|
listenCallback: undefined,
|
|
31
33
|
encoding: ENCODINGS.json,
|
|
32
34
|
ssl: null,
|
|
33
|
-
server: undefined
|
|
35
|
+
server: undefined,
|
|
36
|
+
corsOptions: undefined,
|
|
34
37
|
};
|
|
35
38
|
|
|
36
39
|
/**
|
|
@@ -49,6 +52,7 @@ function BaseHttpServer(options = {}) {
|
|
|
49
52
|
} else if (this.encoding === ENCODINGS.urlencoded) {
|
|
50
53
|
this.app.use(bodyParser.urlencoded({ extended: true }));
|
|
51
54
|
}
|
|
55
|
+
this.app.use(cors(this.options.corsOptions));
|
|
52
56
|
|
|
53
57
|
this.services.forEach(service => this.app[service.method](service.serviceName, service.function));
|
|
54
58
|
this.publicPaths.forEach(public_path => this.app.use(express.static(path.join(process.cwd(), public_path))));
|