caccl-dev-server 2.0.0-beta.10

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Harvard Edtech
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,2 @@
1
+ # caccl-dev-server
2
+ HTTPS server for development of CACCL apps
package/lib/index.d.ts ADDED
@@ -0,0 +1,14 @@
1
+ import express from 'express';
2
+ /**
3
+ * Serve an express app on the given port. Uses HTTPS and a self-signed
4
+ * certificate
5
+ * @author Gabe Abrams
6
+ * @param opts object containing all arguments
7
+ * @param opts.app the express app to serve
8
+ * @param [opts.port=8080] port number to serve on
9
+ */
10
+ declare const serve: (opts: {
11
+ app: express.Application;
12
+ port: number;
13
+ }) => void;
14
+ export default serve;
package/lib/index.js ADDED
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ var selfsigned_1 = __importDefault(require("selfsigned"));
7
+ var https_1 = __importDefault(require("https"));
8
+ /**
9
+ * Serve an express app on the given port. Uses HTTPS and a self-signed
10
+ * certificate
11
+ * @author Gabe Abrams
12
+ * @param opts object containing all arguments
13
+ * @param opts.app the express app to serve
14
+ * @param [opts.port=8080] port number to serve on
15
+ */
16
+ var serve = function (opts) {
17
+ var _a;
18
+ // Destructure opts
19
+ var app = opts.app;
20
+ var port = ((_a = opts.port) !== null && _a !== void 0 ? _a : 8080);
21
+ // Generate certs
22
+ var pems = selfsigned_1.default.generate({ name: "CACCL Dev Server on ".concat(port), value: "localhost:".concat(port) }, { days: 365 });
23
+ // Create a server
24
+ var server = https_1.default.createServer({ key: pems.private, cert: pems.cert }, app);
25
+ // Start listening
26
+ server.listen(port);
27
+ server.on('listening', function () {
28
+ console.log("Now listening on port ".concat(port));
29
+ });
30
+ server.on('error', function (err) {
31
+ if (err.message.includes('EADDRINUSE')) {
32
+ console.log("\nPort ".concat(port, " is already in use. Is another app already running?"));
33
+ process.exit(0);
34
+ }
35
+ console.log("\nCould not start simulator because an error occurred: ".concat(err.message));
36
+ process.exit(0);
37
+ });
38
+ };
39
+ exports.default = serve;
40
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;AACA,0DAAoC;AACpC,gDAA0B;AAE1B;;;;;;;GAOG;AACH,IAAM,KAAK,GAAG,UACZ,IAGC;;IAED,mBAAmB;IACX,IAAA,GAAG,GAAK,IAAI,IAAT,CAAU;IACrB,IAAM,IAAI,GAAG,CAAC,MAAA,IAAI,CAAC,IAAI,mCAAI,IAAI,CAAC,CAAC;IAEjC,iBAAiB;IACjB,IAAM,IAAI,GAAG,oBAAU,CAAC,QAAQ,CAC9B,EAAE,IAAI,EAAE,8BAAuB,IAAI,CAAE,EAAE,KAAK,EAAE,oBAAa,IAAI,CAAE,EAAE,EACnE,EAAE,IAAI,EAAE,GAAG,EAAE,CACd,CAAC;IAEF,kBAAkB;IAClB,IAAM,MAAM,GAAG,eAAK,CAAC,YAAY,CAC/B,EAAE,GAAG,EAAE,IAAI,CAAC,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,EACtC,GAAG,CACJ,CAAC;IAEF,kBAAkB;IAClB,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACpB,MAAM,CAAC,EAAE,CACP,WAAW,EACX;QACE,OAAO,CAAC,GAAG,CAAC,gCAAyB,IAAI,CAAE,CAAC,CAAC;IAC/C,CAAC,CACF,CAAC;IACF,MAAM,CAAC,EAAE,CACP,OAAO,EACP,UAAC,GAAG;QACF,IAAI,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAC,EAAE;YACtC,OAAO,CAAC,GAAG,CAAC,iBAAU,IAAI,wDAAqD,CAAC,CAAC;YACjF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;SACjB;QAED,OAAO,CAAC,GAAG,CAAC,iEAA0D,GAAG,CAAC,OAAO,CAAE,CAAC,CAAC;QACrF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC,CACF,CAAC;AACJ,CAAC,CAAC;AAEF,kBAAe,KAAK,CAAC"}
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "caccl-dev-server",
3
+ "version": "2.0.0-beta.10",
4
+ "description": "HTTPS server for development of CACCL apps",
5
+ "main": "./lib/index.js",
6
+ "types": "./lib/index.d.ts",
7
+ "scripts": {
8
+ "build": "tsc --project ./tsconfig.json"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/harvard-edtech/caccl-dev-server.git"
13
+ },
14
+ "keywords": [
15
+ "CACCL",
16
+ "Server",
17
+ "HTTPS"
18
+ ],
19
+ "author": "Gabe Abrams <gabeabrams@gmail.com>",
20
+ "license": "MIT",
21
+ "bugs": {
22
+ "url": "https://github.com/harvard-edtech/caccl-dev-server/issues"
23
+ },
24
+ "homepage": "https://github.com/harvard-edtech/caccl-dev-server#readme",
25
+ "devDependencies": {
26
+ "typescript": "^4.6.2"
27
+ },
28
+ "dependencies": {
29
+ "@types/express": "^4.17.13",
30
+ "express": "^4.17.3",
31
+ "https": "^1.0.0",
32
+ "selfsigned": "^2.0.0"
33
+ }
34
+ }
package/src/index.ts ADDED
@@ -0,0 +1,57 @@
1
+ import express from 'express';
2
+ import selfsigned from 'selfsigned';
3
+ import https from 'https';
4
+
5
+ /**
6
+ * Serve an express app on the given port. Uses HTTPS and a self-signed
7
+ * certificate
8
+ * @author Gabe Abrams
9
+ * @param opts object containing all arguments
10
+ * @param opts.app the express app to serve
11
+ * @param [opts.port=8080] port number to serve on
12
+ */
13
+ const serve = (
14
+ opts: {
15
+ app: express.Application,
16
+ port: number,
17
+ },
18
+ ) => {
19
+ // Destructure opts
20
+ const { app } = opts;
21
+ const port = (opts.port ?? 8080);
22
+
23
+ // Generate certs
24
+ const pems = selfsigned.generate(
25
+ { name: `CACCL Dev Server on ${port}`, value: `localhost:${port}` },
26
+ { days: 365 },
27
+ );
28
+
29
+ // Create a server
30
+ const server = https.createServer(
31
+ { key: pems.private, cert: pems.cert },
32
+ app,
33
+ );
34
+
35
+ // Start listening
36
+ server.listen(port);
37
+ server.on(
38
+ 'listening',
39
+ () => {
40
+ console.log(`Now listening on port ${port}`);
41
+ },
42
+ );
43
+ server.on(
44
+ 'error',
45
+ (err) => {
46
+ if (err.message.includes('EADDRINUSE')) {
47
+ console.log(`\nPort ${port} is already in use. Is another app already running?`);
48
+ process.exit(0);
49
+ }
50
+
51
+ console.log(`\nCould not start simulator because an error occurred: ${err.message}`);
52
+ process.exit(0);
53
+ },
54
+ );
55
+ };
56
+
57
+ export default serve;
@@ -0,0 +1,8 @@
1
+ type gen = {
2
+ default: (attrs: any, config: { days: number }) => { private: string, public: string, cert: string }
3
+ }
4
+
5
+ declare module 'selfsigned' {
6
+ const x: any;
7
+ export default x;
8
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "compilerOptions": {
3
+ "module": "commonjs",
4
+ "esModuleInterop": true,
5
+ "noImplicitAny": true,
6
+ "noEmitOnError": true,
7
+ "removeComments": false,
8
+ "declaration": true,
9
+ "sourceMap": true,
10
+ "target": "es5",
11
+ "outDir": "./lib"
12
+ },
13
+ "include": [
14
+ "./src"
15
+ ],
16
+ "ts-node": {
17
+ "files": true
18
+ }
19
+ }