redweb 0.4.8 → 0.5.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/package.json CHANGED
@@ -1,18 +1,20 @@
1
1
  {
2
2
  "name": "redweb",
3
- "version": "0.4.8",
3
+ "version": "0.5.0",
4
4
  "description": "A way to quickly set up an express server",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
7
  "test": "node tester.js"
8
8
  },
9
9
  "files": [
10
- "src/*", "index.d.ts"
10
+ "src/*",
11
+ "index.d.ts"
11
12
  ],
12
13
  "keywords": [],
13
14
  "author": "",
14
15
  "license": "ISC",
15
16
  "dependencies": {
17
+ "cors": "^2.8.5",
16
18
  "express": "^4.19.2",
17
19
  "ws": "^8.17.0"
18
20
  },
@@ -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))));