redweb 0.4.3 → 0.4.5
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 +155 -0
- package/package.json +2 -2
package/index.d.ts
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
declare module 'redweb' {
|
|
2
|
+
import { IncomingMessage, ServerResponse } from 'http';
|
|
3
|
+
import { Server as HTTPServer } from 'http';
|
|
4
|
+
import { Server as HTTPSServer } from 'https';
|
|
5
|
+
import WebSocket from 'ws';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* RedWeb encoding types.
|
|
9
|
+
*/
|
|
10
|
+
export type RedWebEncoding = 'json' | 'urlencoded';
|
|
11
|
+
|
|
12
|
+
/**
|
|
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: IncomingMessage, res: ServerResponse) => void;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Options for configuring a RedWeb server.
|
|
23
|
+
*/
|
|
24
|
+
export interface RedWebOptions {
|
|
25
|
+
port?: number;
|
|
26
|
+
bind?: string;
|
|
27
|
+
publicPaths?: string[];
|
|
28
|
+
services?: Service[];
|
|
29
|
+
listenCallback?: () => void;
|
|
30
|
+
encoding?: RedWebEncoding;
|
|
31
|
+
ssl?: {
|
|
32
|
+
key: string;
|
|
33
|
+
cert: string;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Options for configuring a WebSocket server.
|
|
39
|
+
*/
|
|
40
|
+
export interface SocketServerOptions {
|
|
41
|
+
port?: number;
|
|
42
|
+
connectionOpenCallback?: (socket: WebSocket) => void;
|
|
43
|
+
connectionCloseCallback?: (socket: WebSocket) => void;
|
|
44
|
+
messageCallback?: (socket: WebSocket, message: string) => void;
|
|
45
|
+
messageHandlers?: {
|
|
46
|
+
[type: string]: (socket: WebSocket, data: any) => void;
|
|
47
|
+
};
|
|
48
|
+
ssl?: {
|
|
49
|
+
key: string;
|
|
50
|
+
cert: string;
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Base class for HTTP servers.
|
|
56
|
+
*/
|
|
57
|
+
export class BaseHttpServer {
|
|
58
|
+
app: any;
|
|
59
|
+
port: number;
|
|
60
|
+
publicPaths: string[];
|
|
61
|
+
services: Service[];
|
|
62
|
+
listenCallback?: () => void;
|
|
63
|
+
encoding: RedWebEncoding;
|
|
64
|
+
ssl?: { key: string; cert: string; };
|
|
65
|
+
|
|
66
|
+
constructor(options?: RedWebOptions);
|
|
67
|
+
|
|
68
|
+
// Additional methods can be added as needed.
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* HTTP server class.
|
|
73
|
+
*/
|
|
74
|
+
export class HttpServer extends BaseHttpServer {
|
|
75
|
+
constructor(options?: RedWebOptions);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* HTTPS server class.
|
|
80
|
+
*/
|
|
81
|
+
export class HttpsServer extends BaseHttpServer {
|
|
82
|
+
constructor(options?: RedWebOptions);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Base class for WebSocket servers.
|
|
87
|
+
*/
|
|
88
|
+
export class BaseSocketServer {
|
|
89
|
+
wss: WebSocket.Server;
|
|
90
|
+
clients: Map<string, WebSocket>;
|
|
91
|
+
port: number;
|
|
92
|
+
connectionOpenCallback?: (socket: WebSocket) => void;
|
|
93
|
+
connectionCloseCallback?: (socket: WebSocket) => void;
|
|
94
|
+
messageCallback?: (socket: WebSocket, message: string) => void;
|
|
95
|
+
messageHandlers?: { [type: string]: (socket: WebSocket, data: any) => void; };
|
|
96
|
+
ssl?: { key: string; cert: string; };
|
|
97
|
+
|
|
98
|
+
constructor(server: HTTPServer | HTTPSServer, options?: SocketServerOptions);
|
|
99
|
+
|
|
100
|
+
handleConnection(socket: WebSocket, req: IncomingMessage): void;
|
|
101
|
+
handleMessage(socket: WebSocket, message: string, ip: string): void;
|
|
102
|
+
handleClose(socket: WebSocket, ip: string): void;
|
|
103
|
+
handleError(socket: WebSocket, error: Error, ip: string): void;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* WebSocket server class.
|
|
108
|
+
*/
|
|
109
|
+
export class SocketServer extends BaseSocketServer {
|
|
110
|
+
constructor(options?: SocketServerOptions);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Secure WebSocket server class.
|
|
115
|
+
*/
|
|
116
|
+
export class SecureSocketServer extends BaseSocketServer {
|
|
117
|
+
constructor(options?: SocketServerOptions);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* SSL configuration loader.
|
|
122
|
+
*/
|
|
123
|
+
export function loadSslConfig(sslOptions: { key: string; cert: string; }): { key: string; cert: string; };
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Constants for encoding types.
|
|
127
|
+
*/
|
|
128
|
+
export const ENCODINGS: {
|
|
129
|
+
json: 'json';
|
|
130
|
+
urlencoded: 'urlencoded';
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Constants for HTTP methods.
|
|
135
|
+
*/
|
|
136
|
+
export const METHODS: {
|
|
137
|
+
POST: 'post';
|
|
138
|
+
GET: 'get';
|
|
139
|
+
PUT: 'put';
|
|
140
|
+
DELETE: 'delete';
|
|
141
|
+
PATCH: 'patch';
|
|
142
|
+
OPTIONS: 'options';
|
|
143
|
+
HEAD: 'head';
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Default HTTP options.
|
|
148
|
+
*/
|
|
149
|
+
export const HTTP_OPTIONS: RedWebOptions;
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Default socket options.
|
|
153
|
+
*/
|
|
154
|
+
export const SOCKET_OPTIONS: SocketServerOptions;
|
|
155
|
+
}
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "redweb",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.5",
|
|
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/*"
|
|
10
|
+
"src/*", "index.d.ts"
|
|
11
11
|
],
|
|
12
12
|
"keywords": [],
|
|
13
13
|
"author": "",
|