quidproquo-dev-server 0.0.239 → 0.0.240

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.
@@ -2,3 +2,4 @@ export * from './apiImplementation';
2
2
  export * from './eventBusImplementation';
3
3
  export * from './queueImplementation';
4
4
  export * from './serviceFunctionImplementation';
5
+ export * from './webSocketImplementation';
@@ -18,3 +18,4 @@ __exportStar(require("./apiImplementation"), exports);
18
18
  __exportStar(require("./eventBusImplementation"), exports);
19
19
  __exportStar(require("./queueImplementation"), exports);
20
20
  __exportStar(require("./serviceFunctionImplementation"), exports);
21
+ __exportStar(require("./webSocketImplementation"), exports);
@@ -0,0 +1,2 @@
1
+ import { DevServerConfig } from '../types';
2
+ export declare const webSocketImplementation: (devServerConfig: DevServerConfig) => Promise<void>;
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.webSocketImplementation = void 0;
13
+ const http_1 = require("http");
14
+ const ws_1 = require("ws");
15
+ const webSocketImplementation = (devServerConfig) => __awaiter(void 0, void 0, void 0, function* () {
16
+ if (!devServerConfig.webSocketPort) {
17
+ return;
18
+ }
19
+ console.log('Starting WebSocket Server!');
20
+ const server = (0, http_1.createServer)();
21
+ const wss1 = new ws_1.WebSocketServer({ noServer: true });
22
+ const wss2 = new ws_1.WebSocketServer({ noServer: true });
23
+ wss1.on('connection', (ws) => {
24
+ ws.on('error', console.error);
25
+ ws.on('message', (data) => {
26
+ console.log('received: %s', data);
27
+ });
28
+ ws.on('close', () => {
29
+ console.log('disconnected');
30
+ });
31
+ // ...
32
+ });
33
+ wss2.on('connection', (ws) => {
34
+ ws.on('error', console.error);
35
+ ws.on('message', (data) => {
36
+ console.log('received: %s', data);
37
+ });
38
+ ws.on('close', () => {
39
+ console.log('disconnected');
40
+ });
41
+ // ...
42
+ });
43
+ server.on('upgrade', (request, socket, head) => {
44
+ const { pathname } = new URL(request.url || '', 'wss://base.url');
45
+ if (pathname === '/foo') {
46
+ wss1.handleUpgrade(request, socket, head, (ws) => {
47
+ wss1.emit('connection', ws, request);
48
+ });
49
+ }
50
+ else if (pathname === '/bar') {
51
+ wss2.handleUpgrade(request, socket, head, (ws) => {
52
+ wss2.emit('connection', ws, request);
53
+ });
54
+ }
55
+ else {
56
+ socket.destroy();
57
+ }
58
+ });
59
+ server.listen(devServerConfig.webSocketPort, 'localhost');
60
+ // Never ends
61
+ yield new Promise(() => { });
62
+ });
63
+ exports.webSocketImplementation = webSocketImplementation;
@@ -33,6 +33,7 @@ const startDevServer = (devServerConfig) => __awaiter(void 0, void 0, void 0, fu
33
33
  (0, implementations_1.serviceFunctionImplementation)(devServerConfig),
34
34
  (0, implementations_1.eventBusImplementation)(devServerConfig),
35
35
  (0, implementations_1.queueImplementation)(devServerConfig),
36
+ (0, implementations_1.webSocketImplementation)(devServerConfig),
36
37
  ]);
37
38
  });
38
39
  exports.startDevServer = startDevServer;
@@ -1,7 +1,8 @@
1
1
  import { QPQConfig, QpqFunctionRuntime } from 'quidproquo-core';
2
2
  export type DevServerConfig = {
3
3
  serverDomain: 'localhost';
4
- serverPort: 8080;
4
+ serverPort: number;
5
+ webSocketPort?: number;
5
6
  dynamicModuleLoader: <T = any>(serviceName: string, modulePath: QpqFunctionRuntime) => Promise<T>;
6
7
  qpqConfigs: QPQConfig[];
7
8
  };
@@ -2,3 +2,4 @@ export * from './apiImplementation';
2
2
  export * from './eventBusImplementation';
3
3
  export * from './queueImplementation';
4
4
  export * from './serviceFunctionImplementation';
5
+ export * from './webSocketImplementation';
@@ -2,3 +2,4 @@ export * from './apiImplementation';
2
2
  export * from './eventBusImplementation';
3
3
  export * from './queueImplementation';
4
4
  export * from './serviceFunctionImplementation';
5
+ export * from './webSocketImplementation';
@@ -0,0 +1,2 @@
1
+ import { DevServerConfig } from '../types';
2
+ export declare const webSocketImplementation: (devServerConfig: DevServerConfig) => Promise<void>;
@@ -0,0 +1,50 @@
1
+ import { createServer } from 'http';
2
+ import { WebSocketServer } from 'ws';
3
+ export const webSocketImplementation = async (devServerConfig) => {
4
+ if (!devServerConfig.webSocketPort) {
5
+ return;
6
+ }
7
+ console.log('Starting WebSocket Server!');
8
+ const server = createServer();
9
+ const wss1 = new WebSocketServer({ noServer: true });
10
+ const wss2 = new WebSocketServer({ noServer: true });
11
+ wss1.on('connection', (ws) => {
12
+ ws.on('error', console.error);
13
+ ws.on('message', (data) => {
14
+ console.log('received: %s', data);
15
+ });
16
+ ws.on('close', () => {
17
+ console.log('disconnected');
18
+ });
19
+ // ...
20
+ });
21
+ wss2.on('connection', (ws) => {
22
+ ws.on('error', console.error);
23
+ ws.on('message', (data) => {
24
+ console.log('received: %s', data);
25
+ });
26
+ ws.on('close', () => {
27
+ console.log('disconnected');
28
+ });
29
+ // ...
30
+ });
31
+ server.on('upgrade', (request, socket, head) => {
32
+ const { pathname } = new URL(request.url || '', 'wss://base.url');
33
+ if (pathname === '/foo') {
34
+ wss1.handleUpgrade(request, socket, head, (ws) => {
35
+ wss1.emit('connection', ws, request);
36
+ });
37
+ }
38
+ else if (pathname === '/bar') {
39
+ wss2.handleUpgrade(request, socket, head, (ws) => {
40
+ wss2.emit('connection', ws, request);
41
+ });
42
+ }
43
+ else {
44
+ socket.destroy();
45
+ }
46
+ });
47
+ server.listen(devServerConfig.webSocketPort, 'localhost');
48
+ // Never ends
49
+ await new Promise(() => { });
50
+ };
package/lib/esm/main.js CHANGED
@@ -1,4 +1,4 @@
1
- import { apiImplementation, eventBusImplementation, queueImplementation, serviceFunctionImplementation } from './implementations';
1
+ import { apiImplementation, eventBusImplementation, queueImplementation, serviceFunctionImplementation, webSocketImplementation, } from './implementations';
2
2
  export * from './implementations';
3
3
  export const startDevServer = async (devServerConfig) => {
4
4
  console.log('Starting QPQ Dev Server!!!');
@@ -7,5 +7,6 @@ export const startDevServer = async (devServerConfig) => {
7
7
  serviceFunctionImplementation(devServerConfig),
8
8
  eventBusImplementation(devServerConfig),
9
9
  queueImplementation(devServerConfig),
10
+ webSocketImplementation(devServerConfig),
10
11
  ]);
11
12
  };
@@ -1,7 +1,8 @@
1
1
  import { QPQConfig, QpqFunctionRuntime } from 'quidproquo-core';
2
2
  export type DevServerConfig = {
3
3
  serverDomain: 'localhost';
4
- serverPort: 8080;
4
+ serverPort: number;
5
+ webSocketPort?: number;
5
6
  dynamicModuleLoader: <T = any>(serviceName: string, modulePath: QpqFunctionRuntime) => Promise<T>;
6
7
  qpqConfigs: QPQConfig[];
7
8
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "quidproquo-dev-server",
3
- "version": "0.0.239",
3
+ "version": "0.0.240",
4
4
  "description": "",
5
5
  "main": "./lib/commonjs/index.js",
6
6
  "module": "./lib/esm/index.js",
@@ -33,14 +33,15 @@
33
33
  "homepage": "https://github.com/joe-coady/quidproquo#readme",
34
34
  "dependencies": {
35
35
  "multer": "^1.4.5-lts.1",
36
- "quidproquo-core": "0.0.239",
37
- "quidproquo-webserver": "0.0.239",
38
- "quidproquo-actionprocessor-awslambda": "0.0.239",
39
- "quidproquo-actionprocessor-node": "0.0.239"
36
+ "quidproquo-actionprocessor-awslambda": "0.0.240",
37
+ "quidproquo-actionprocessor-node": "0.0.240",
38
+ "quidproquo-core": "0.0.240",
39
+ "quidproquo-webserver": "0.0.240",
40
+ "ws": "^8.18.0"
40
41
  },
41
42
  "devDependencies": {
42
43
  "@types/multer": "^1.4.12",
43
- "quidproquo-tsconfig": "0.0.239",
44
+ "quidproquo-tsconfig": "0.0.240",
44
45
  "typescript": "^4.9.3"
45
46
  }
46
47
  }