redweb 0.0.1

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.
Files changed (2) hide show
  1. package/index.js +39 -0
  2. package/package.json +18 -0
package/index.js ADDED
@@ -0,0 +1,39 @@
1
+ const express = require('express');
2
+ const bodyParser = require('body-parser');
3
+ const path = require('path');
4
+
5
+ const DEFAULT_OPTIONS = {
6
+ port: 80,
7
+ bind: '0.0.0.0',
8
+ public: ['./public'],
9
+ services: [],
10
+ listenCallback: undefined
11
+ }
12
+
13
+ /**
14
+ * To get started with WebExpress, simply initialize your WebExpress instance:
15
+ * ```javascript
16
+ * const app = new WebExpress();
17
+ * ```
18
+ * You can also configure it according to your needs:
19
+ * ```javascript
20
+ * const app = new WebExpress({
21
+ * port: 3000,
22
+ * public: [
23
+ * './pages/my_public_html',
24
+ * './content/my_public_images',
25
+ * './styles/styles.css']
26
+ * }
27
+ * );
28
+ * ```
29
+ *
30
+ * @param {{port: Number, bind: String, public: Array<String>, services: []}} options
31
+ * @return WebExpress
32
+ */
33
+ export function WebExpress(options = DEFAULT_OPTIONS) {
34
+ const app = express();
35
+ app.use(bodyParser.json());
36
+ options.public.forEach((public_path) => app.use(express.static(path.join(__dirname, public_path))));
37
+ app.listen(options.port, listenCallback ? listenCallback : () => console.log('WebExpress listening on port ' + options.port));
38
+ return this;
39
+ }
package/package.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "name": "redweb",
3
+ "version": "0.0.1",
4
+ "description": "A way to quickly set up an express server",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
9
+ "keywords": [],
10
+ "author": "",
11
+ "license": "ISC",
12
+ "dependencies": {
13
+ "express": "^4.19.2"
14
+ },
15
+ "devDependencies": {
16
+ "@types/express": "^4.17.21"
17
+ }
18
+ }