redweb 0.4.4 → 0.4.6
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/index.d.ts +27 -13
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ declare module 'redweb' {
|
|
|
2
2
|
import { Request, Response } from 'express';
|
|
3
3
|
import { Server as HTTPServer } from 'http';
|
|
4
4
|
import { Server as HTTPSServer } from 'https';
|
|
5
|
-
import
|
|
5
|
+
import WebSocket from 'ws';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* RedWeb encoding types.
|
|
@@ -10,13 +10,22 @@ declare module 'redweb' {
|
|
|
10
10
|
export type RedWebEncoding = 'json' | 'urlencoded';
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
13
|
+
* Service configuration for RedWeb.
|
|
14
|
+
*/
|
|
15
|
+
export interface Service {
|
|
16
|
+
serviceName: string;
|
|
17
|
+
method: 'get' | 'post' | 'put' | 'delete' | 'patch' | 'options' | 'head';
|
|
18
|
+
function: (req: Request, res: Response) => void;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Options for configuring a RedWeb server.
|
|
14
23
|
*/
|
|
15
24
|
export interface RedWebOptions {
|
|
16
25
|
port?: number;
|
|
17
26
|
bind?: string;
|
|
18
27
|
publicPaths?: string[];
|
|
19
|
-
services?:
|
|
28
|
+
services?: Service[];
|
|
20
29
|
listenCallback?: () => void;
|
|
21
30
|
encoding?: RedWebEncoding;
|
|
22
31
|
ssl?: {
|
|
@@ -26,7 +35,7 @@ declare module 'redweb' {
|
|
|
26
35
|
}
|
|
27
36
|
|
|
28
37
|
/**
|
|
29
|
-
*
|
|
38
|
+
* Options for configuring a WebSocket server.
|
|
30
39
|
*/
|
|
31
40
|
export interface SocketServerOptions {
|
|
32
41
|
port?: number;
|
|
@@ -43,13 +52,13 @@ declare module 'redweb' {
|
|
|
43
52
|
}
|
|
44
53
|
|
|
45
54
|
/**
|
|
46
|
-
* Base HTTP
|
|
55
|
+
* Base class for HTTP servers.
|
|
47
56
|
*/
|
|
48
57
|
export class BaseHttpServer {
|
|
49
58
|
app: any;
|
|
50
59
|
port: number;
|
|
51
60
|
publicPaths: string[];
|
|
52
|
-
services:
|
|
61
|
+
services: Service[];
|
|
53
62
|
listenCallback?: () => void;
|
|
54
63
|
encoding: RedWebEncoding;
|
|
55
64
|
ssl?: { key: string; cert: string; };
|
|
@@ -60,24 +69,24 @@ declare module 'redweb' {
|
|
|
60
69
|
}
|
|
61
70
|
|
|
62
71
|
/**
|
|
63
|
-
* HTTP server.
|
|
72
|
+
* HTTP server class.
|
|
64
73
|
*/
|
|
65
74
|
export class HttpServer extends BaseHttpServer {
|
|
66
75
|
constructor(options?: RedWebOptions);
|
|
67
76
|
}
|
|
68
77
|
|
|
69
78
|
/**
|
|
70
|
-
* HTTPS server.
|
|
79
|
+
* HTTPS server class.
|
|
71
80
|
*/
|
|
72
81
|
export class HttpsServer extends BaseHttpServer {
|
|
73
82
|
constructor(options?: RedWebOptions);
|
|
74
83
|
}
|
|
75
84
|
|
|
76
85
|
/**
|
|
77
|
-
* Base
|
|
86
|
+
* Base class for WebSocket servers.
|
|
78
87
|
*/
|
|
79
88
|
export class BaseSocketServer {
|
|
80
|
-
wss:
|
|
89
|
+
wss: WebSocket.Server;
|
|
81
90
|
clients: Map<string, WebSocket>;
|
|
82
91
|
port: number;
|
|
83
92
|
connectionOpenCallback?: (socket: WebSocket) => void;
|
|
@@ -88,21 +97,21 @@ declare module 'redweb' {
|
|
|
88
97
|
|
|
89
98
|
constructor(server: HTTPServer | HTTPSServer, options?: SocketServerOptions);
|
|
90
99
|
|
|
91
|
-
handleConnection(socket: WebSocket, req:
|
|
100
|
+
handleConnection(socket: WebSocket, req: Request): void;
|
|
92
101
|
handleMessage(socket: WebSocket, message: string, ip: string): void;
|
|
93
102
|
handleClose(socket: WebSocket, ip: string): void;
|
|
94
103
|
handleError(socket: WebSocket, error: Error, ip: string): void;
|
|
95
104
|
}
|
|
96
105
|
|
|
97
106
|
/**
|
|
98
|
-
* WebSocket server.
|
|
107
|
+
* WebSocket server class.
|
|
99
108
|
*/
|
|
100
109
|
export class SocketServer extends BaseSocketServer {
|
|
101
110
|
constructor(options?: SocketServerOptions);
|
|
102
111
|
}
|
|
103
112
|
|
|
104
113
|
/**
|
|
105
|
-
* Secure WebSocket server.
|
|
114
|
+
* Secure WebSocket server class.
|
|
106
115
|
*/
|
|
107
116
|
export class SecureSocketServer extends BaseSocketServer {
|
|
108
117
|
constructor(options?: SocketServerOptions);
|
|
@@ -127,6 +136,11 @@ declare module 'redweb' {
|
|
|
127
136
|
export const METHODS: {
|
|
128
137
|
POST: 'post';
|
|
129
138
|
GET: 'get';
|
|
139
|
+
PUT: 'put';
|
|
140
|
+
DELETE: 'delete';
|
|
141
|
+
PATCH: 'patch';
|
|
142
|
+
OPTIONS: 'options';
|
|
143
|
+
HEAD: 'head';
|
|
130
144
|
};
|
|
131
145
|
|
|
132
146
|
/**
|