mikroserve 0.0.2 → 0.0.4
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/README.md +178 -1
- package/lib/MikroServe.d.mts +21 -41
- package/lib/MikroServe.d.ts +21 -41
- package/lib/MikroServe.js +102 -78
- package/lib/MikroServe.mjs +3 -1
- package/lib/{chunk-GGGGATKH.mjs → chunk-6UXWR6LD.mjs} +81 -78
- package/lib/chunk-CQPU7577.mjs +9 -0
- package/lib/chunk-RP67R3W4.mjs +43 -0
- package/lib/index.d.mts +2 -1
- package/lib/index.d.ts +2 -1
- package/lib/index.js +118 -78
- package/lib/index.mjs +19 -1
- package/lib/interfaces/index.d.mts +71 -207
- package/lib/interfaces/index.d.ts +71 -207
- package/lib/utils/configDefaults.d.mts +20 -0
- package/lib/utils/configDefaults.d.ts +20 -0
- package/lib/utils/configDefaults.js +72 -0
- package/lib/utils/configDefaults.mjs +9 -0
- package/lib/utils/getTruthyEnvValue.d.mts +6 -0
- package/lib/utils/getTruthyEnvValue.d.ts +6 -0
- package/lib/utils/getTruthyEnvValue.js +33 -0
- package/lib/utils/getTruthyEnvValue.mjs +6 -0
- package/package.json +5 -3
|
@@ -1,193 +1,74 @@
|
|
|
1
1
|
import http from 'node:http';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* @description
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
interface JwtPayload {
|
|
61
|
-
sub: string;
|
|
62
|
-
jti: string;
|
|
63
|
-
iat?: number;
|
|
64
|
-
exp?: number;
|
|
65
|
-
lastLogin: number;
|
|
66
|
-
metadata?: {
|
|
67
|
-
ip?: string;
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* JWT payload structure
|
|
72
|
-
*/
|
|
73
|
-
interface JwtPayload {
|
|
74
|
-
sub: string;
|
|
75
|
-
jti: string;
|
|
76
|
-
iat?: number;
|
|
77
|
-
exp?: number;
|
|
78
|
-
lastLogin: number;
|
|
79
|
-
metadata?: {
|
|
80
|
-
ip?: string;
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
interface RequestContext {
|
|
84
|
-
body?: Record<string, any>;
|
|
85
|
-
query?: Record<string, any>;
|
|
86
|
-
headers?: Record<string, any>;
|
|
87
|
-
ip?: string;
|
|
88
|
-
log?: {
|
|
89
|
-
error: (message: string, error: Error) => void;
|
|
90
|
-
info?: (message: string, ...args: any[]) => void;
|
|
91
|
-
};
|
|
92
|
-
user?: {
|
|
93
|
-
email: string;
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* Request context interface
|
|
98
|
-
*/
|
|
99
|
-
interface RequestContext {
|
|
100
|
-
body?: Record<string, any>;
|
|
101
|
-
query?: Record<string, any>;
|
|
102
|
-
headers?: Record<string, any>;
|
|
103
|
-
ip?: string;
|
|
104
|
-
log?: {
|
|
105
|
-
error: (message: string, error: Error) => void;
|
|
106
|
-
info?: (message: string, ...args: any[]) => void;
|
|
107
|
-
};
|
|
108
|
-
user?: {
|
|
109
|
-
email: string;
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
interface MagicLinkRequest {
|
|
113
|
-
email: string;
|
|
114
|
-
ip?: string;
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* Magic link request parameters
|
|
118
|
-
*/
|
|
119
|
-
interface MagicLinkRequest {
|
|
120
|
-
email: string;
|
|
121
|
-
ip?: string;
|
|
122
|
-
}
|
|
123
|
-
interface MagicLinkUrlParams {
|
|
124
|
-
token: string;
|
|
125
|
-
email: string;
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* Parameters for creating a magic link URL
|
|
129
|
-
*/
|
|
130
|
-
interface MagicLinkUrlParams {
|
|
131
|
-
token: string;
|
|
132
|
-
email: string;
|
|
133
|
-
}
|
|
134
|
-
interface VerifyTokenRequest {
|
|
135
|
-
token: string;
|
|
136
|
-
email: string;
|
|
137
|
-
}
|
|
138
|
-
/**
|
|
139
|
-
* Verify token request parameters
|
|
140
|
-
*/
|
|
141
|
-
interface VerifyTokenRequest {
|
|
142
|
-
token: string;
|
|
143
|
-
email: string;
|
|
144
|
-
}
|
|
145
|
-
interface SessionInfo {
|
|
146
|
-
id: string;
|
|
147
|
-
createdAt: number;
|
|
148
|
-
lastLogin: number;
|
|
149
|
-
lastUsed?: number;
|
|
150
|
-
metadata?: {
|
|
151
|
-
ip?: string;
|
|
152
|
-
};
|
|
153
|
-
isCurrentSession?: boolean;
|
|
154
|
-
}
|
|
155
|
-
/**
|
|
156
|
-
* Session information interface
|
|
157
|
-
*/
|
|
158
|
-
interface SessionInfo {
|
|
159
|
-
id: string;
|
|
160
|
-
createdAt: number;
|
|
161
|
-
lastLogin: number;
|
|
162
|
-
lastUsed?: number;
|
|
163
|
-
metadata?: {
|
|
164
|
-
ip?: string;
|
|
4
|
+
* @description Server configuration options.
|
|
5
|
+
*/
|
|
6
|
+
type MikroServeConfiguration = {
|
|
7
|
+
/**
|
|
8
|
+
* The port to expose.
|
|
9
|
+
* @default process.env.PORT
|
|
10
|
+
* @default 3000
|
|
11
|
+
*/
|
|
12
|
+
port: number;
|
|
13
|
+
/**
|
|
14
|
+
* The host name to use.
|
|
15
|
+
* @default process.env.HOST
|
|
16
|
+
* @default '0.0.0.0'
|
|
17
|
+
*/
|
|
18
|
+
host: string;
|
|
19
|
+
/**
|
|
20
|
+
* Should the server use HTTPS?
|
|
21
|
+
* @default false
|
|
22
|
+
*/
|
|
23
|
+
useHttps: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* The path to the SSL certificate.
|
|
26
|
+
* @default '''
|
|
27
|
+
*/
|
|
28
|
+
sslCert: string;
|
|
29
|
+
/**
|
|
30
|
+
* The path to the SSL key.
|
|
31
|
+
* @default ''
|
|
32
|
+
*/
|
|
33
|
+
sslKey: string;
|
|
34
|
+
/**
|
|
35
|
+
* The path to the SSL CA file.
|
|
36
|
+
* @default ''
|
|
37
|
+
*/
|
|
38
|
+
sslCa: string;
|
|
39
|
+
/**
|
|
40
|
+
* Use debug mode?
|
|
41
|
+
* @default process.env.DEBUG
|
|
42
|
+
* @default false
|
|
43
|
+
*/
|
|
44
|
+
debug: boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Rate limiter settings.
|
|
47
|
+
*/
|
|
48
|
+
rateLimit: {
|
|
49
|
+
/**
|
|
50
|
+
* Should the rate limiter be active?
|
|
51
|
+
* @default true
|
|
52
|
+
*/
|
|
53
|
+
enabled: boolean;
|
|
54
|
+
/**
|
|
55
|
+
* What is the maximum requests per minute from a given IP address?
|
|
56
|
+
* @default 100
|
|
57
|
+
*/
|
|
58
|
+
requestsPerMinute: number;
|
|
165
59
|
};
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
tokenType: string;
|
|
173
|
-
}
|
|
174
|
-
/**
|
|
175
|
-
* Token response interface
|
|
176
|
-
*/
|
|
177
|
-
interface TokenResponse {
|
|
178
|
-
accessToken: string;
|
|
179
|
-
refreshToken: string;
|
|
180
|
-
expiresIn: number;
|
|
181
|
-
tokenType: string;
|
|
182
|
-
}
|
|
60
|
+
/**
|
|
61
|
+
* List of allowed domains.
|
|
62
|
+
* @default ["*"]
|
|
63
|
+
*/
|
|
64
|
+
allowedDomains: string[];
|
|
65
|
+
};
|
|
183
66
|
/**
|
|
184
|
-
*
|
|
67
|
+
* @description Server configuration options.
|
|
185
68
|
*/
|
|
186
|
-
type
|
|
187
|
-
[providerType: string]: Record<string, any>;
|
|
188
|
-
};
|
|
69
|
+
type MikroServeOptions = Partial<MikroServeConfiguration>;
|
|
189
70
|
/**
|
|
190
|
-
* Response utilities for handlers
|
|
71
|
+
* @description Response utilities for handlers.
|
|
191
72
|
*/
|
|
192
73
|
interface ResponseHelpers {
|
|
193
74
|
text(content: string, status?: number): HandlerResponse;
|
|
@@ -198,7 +79,7 @@ interface ResponseHelpers {
|
|
|
198
79
|
status(code: number): ResponseHelpers;
|
|
199
80
|
}
|
|
200
81
|
/**
|
|
201
|
-
* Context object passed to route handlers
|
|
82
|
+
* @description Context object passed to route handlers.
|
|
202
83
|
*/
|
|
203
84
|
interface Context extends ResponseHelpers {
|
|
204
85
|
req: http.IncomingMessage;
|
|
@@ -211,7 +92,7 @@ interface Context extends ResponseHelpers {
|
|
|
211
92
|
state: Record<string, any>;
|
|
212
93
|
}
|
|
213
94
|
/**
|
|
214
|
-
* Handler response object
|
|
95
|
+
* @description Handler response object.
|
|
215
96
|
*/
|
|
216
97
|
interface HandlerResponse {
|
|
217
98
|
statusCode: number;
|
|
@@ -219,15 +100,15 @@ interface HandlerResponse {
|
|
|
219
100
|
headers?: Record<string, string>;
|
|
220
101
|
}
|
|
221
102
|
/**
|
|
222
|
-
* Route handler function signature
|
|
103
|
+
* @description Route handler function signature.
|
|
223
104
|
*/
|
|
224
105
|
type RouteHandler = (context: Context) => Promise<HandlerResponse> | HandlerResponse;
|
|
225
106
|
/**
|
|
226
|
-
* Middleware function signature
|
|
107
|
+
* @description Middleware function signature.
|
|
227
108
|
*/
|
|
228
109
|
type Middleware = (context: Context, next: () => Promise<HandlerResponse>) => Promise<HandlerResponse> | HandlerResponse;
|
|
229
110
|
/**
|
|
230
|
-
* Route definition
|
|
111
|
+
* @description Route definition.
|
|
231
112
|
*/
|
|
232
113
|
interface Route {
|
|
233
114
|
method: string;
|
|
@@ -236,28 +117,11 @@ interface Route {
|
|
|
236
117
|
middlewares: Middleware[];
|
|
237
118
|
}
|
|
238
119
|
/**
|
|
239
|
-
* Path pattern parameter extraction
|
|
120
|
+
* @description Path pattern parameter extraction.
|
|
240
121
|
*/
|
|
241
122
|
interface PathPattern {
|
|
242
123
|
pattern: RegExp;
|
|
243
124
|
paramNames: string[];
|
|
244
125
|
}
|
|
245
|
-
/**
|
|
246
|
-
* Server configuration options
|
|
247
|
-
*/
|
|
248
|
-
interface MikroServeConfiguration {
|
|
249
|
-
port?: number;
|
|
250
|
-
host?: string;
|
|
251
|
-
useHttps?: boolean;
|
|
252
|
-
sslCert?: string;
|
|
253
|
-
sslKey?: string;
|
|
254
|
-
sslCa?: string;
|
|
255
|
-
debug?: boolean;
|
|
256
|
-
rateLimit?: {
|
|
257
|
-
requestsPerMinute: number;
|
|
258
|
-
enabled: boolean;
|
|
259
|
-
};
|
|
260
|
-
allowedDomains?: string[];
|
|
261
|
-
}
|
|
262
126
|
|
|
263
|
-
export type { Context,
|
|
127
|
+
export type { Context, HandlerResponse, Middleware, MikroServeConfiguration, MikroServeOptions, PathPattern, ResponseHelpers, Route, RouteHandler };
|
|
@@ -1,193 +1,74 @@
|
|
|
1
1
|
import http from 'node:http';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* @description
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
interface JwtPayload {
|
|
61
|
-
sub: string;
|
|
62
|
-
jti: string;
|
|
63
|
-
iat?: number;
|
|
64
|
-
exp?: number;
|
|
65
|
-
lastLogin: number;
|
|
66
|
-
metadata?: {
|
|
67
|
-
ip?: string;
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* JWT payload structure
|
|
72
|
-
*/
|
|
73
|
-
interface JwtPayload {
|
|
74
|
-
sub: string;
|
|
75
|
-
jti: string;
|
|
76
|
-
iat?: number;
|
|
77
|
-
exp?: number;
|
|
78
|
-
lastLogin: number;
|
|
79
|
-
metadata?: {
|
|
80
|
-
ip?: string;
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
interface RequestContext {
|
|
84
|
-
body?: Record<string, any>;
|
|
85
|
-
query?: Record<string, any>;
|
|
86
|
-
headers?: Record<string, any>;
|
|
87
|
-
ip?: string;
|
|
88
|
-
log?: {
|
|
89
|
-
error: (message: string, error: Error) => void;
|
|
90
|
-
info?: (message: string, ...args: any[]) => void;
|
|
91
|
-
};
|
|
92
|
-
user?: {
|
|
93
|
-
email: string;
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* Request context interface
|
|
98
|
-
*/
|
|
99
|
-
interface RequestContext {
|
|
100
|
-
body?: Record<string, any>;
|
|
101
|
-
query?: Record<string, any>;
|
|
102
|
-
headers?: Record<string, any>;
|
|
103
|
-
ip?: string;
|
|
104
|
-
log?: {
|
|
105
|
-
error: (message: string, error: Error) => void;
|
|
106
|
-
info?: (message: string, ...args: any[]) => void;
|
|
107
|
-
};
|
|
108
|
-
user?: {
|
|
109
|
-
email: string;
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
interface MagicLinkRequest {
|
|
113
|
-
email: string;
|
|
114
|
-
ip?: string;
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* Magic link request parameters
|
|
118
|
-
*/
|
|
119
|
-
interface MagicLinkRequest {
|
|
120
|
-
email: string;
|
|
121
|
-
ip?: string;
|
|
122
|
-
}
|
|
123
|
-
interface MagicLinkUrlParams {
|
|
124
|
-
token: string;
|
|
125
|
-
email: string;
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* Parameters for creating a magic link URL
|
|
129
|
-
*/
|
|
130
|
-
interface MagicLinkUrlParams {
|
|
131
|
-
token: string;
|
|
132
|
-
email: string;
|
|
133
|
-
}
|
|
134
|
-
interface VerifyTokenRequest {
|
|
135
|
-
token: string;
|
|
136
|
-
email: string;
|
|
137
|
-
}
|
|
138
|
-
/**
|
|
139
|
-
* Verify token request parameters
|
|
140
|
-
*/
|
|
141
|
-
interface VerifyTokenRequest {
|
|
142
|
-
token: string;
|
|
143
|
-
email: string;
|
|
144
|
-
}
|
|
145
|
-
interface SessionInfo {
|
|
146
|
-
id: string;
|
|
147
|
-
createdAt: number;
|
|
148
|
-
lastLogin: number;
|
|
149
|
-
lastUsed?: number;
|
|
150
|
-
metadata?: {
|
|
151
|
-
ip?: string;
|
|
152
|
-
};
|
|
153
|
-
isCurrentSession?: boolean;
|
|
154
|
-
}
|
|
155
|
-
/**
|
|
156
|
-
* Session information interface
|
|
157
|
-
*/
|
|
158
|
-
interface SessionInfo {
|
|
159
|
-
id: string;
|
|
160
|
-
createdAt: number;
|
|
161
|
-
lastLogin: number;
|
|
162
|
-
lastUsed?: number;
|
|
163
|
-
metadata?: {
|
|
164
|
-
ip?: string;
|
|
4
|
+
* @description Server configuration options.
|
|
5
|
+
*/
|
|
6
|
+
type MikroServeConfiguration = {
|
|
7
|
+
/**
|
|
8
|
+
* The port to expose.
|
|
9
|
+
* @default process.env.PORT
|
|
10
|
+
* @default 3000
|
|
11
|
+
*/
|
|
12
|
+
port: number;
|
|
13
|
+
/**
|
|
14
|
+
* The host name to use.
|
|
15
|
+
* @default process.env.HOST
|
|
16
|
+
* @default '0.0.0.0'
|
|
17
|
+
*/
|
|
18
|
+
host: string;
|
|
19
|
+
/**
|
|
20
|
+
* Should the server use HTTPS?
|
|
21
|
+
* @default false
|
|
22
|
+
*/
|
|
23
|
+
useHttps: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* The path to the SSL certificate.
|
|
26
|
+
* @default '''
|
|
27
|
+
*/
|
|
28
|
+
sslCert: string;
|
|
29
|
+
/**
|
|
30
|
+
* The path to the SSL key.
|
|
31
|
+
* @default ''
|
|
32
|
+
*/
|
|
33
|
+
sslKey: string;
|
|
34
|
+
/**
|
|
35
|
+
* The path to the SSL CA file.
|
|
36
|
+
* @default ''
|
|
37
|
+
*/
|
|
38
|
+
sslCa: string;
|
|
39
|
+
/**
|
|
40
|
+
* Use debug mode?
|
|
41
|
+
* @default process.env.DEBUG
|
|
42
|
+
* @default false
|
|
43
|
+
*/
|
|
44
|
+
debug: boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Rate limiter settings.
|
|
47
|
+
*/
|
|
48
|
+
rateLimit: {
|
|
49
|
+
/**
|
|
50
|
+
* Should the rate limiter be active?
|
|
51
|
+
* @default true
|
|
52
|
+
*/
|
|
53
|
+
enabled: boolean;
|
|
54
|
+
/**
|
|
55
|
+
* What is the maximum requests per minute from a given IP address?
|
|
56
|
+
* @default 100
|
|
57
|
+
*/
|
|
58
|
+
requestsPerMinute: number;
|
|
165
59
|
};
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
tokenType: string;
|
|
173
|
-
}
|
|
174
|
-
/**
|
|
175
|
-
* Token response interface
|
|
176
|
-
*/
|
|
177
|
-
interface TokenResponse {
|
|
178
|
-
accessToken: string;
|
|
179
|
-
refreshToken: string;
|
|
180
|
-
expiresIn: number;
|
|
181
|
-
tokenType: string;
|
|
182
|
-
}
|
|
60
|
+
/**
|
|
61
|
+
* List of allowed domains.
|
|
62
|
+
* @default ["*"]
|
|
63
|
+
*/
|
|
64
|
+
allowedDomains: string[];
|
|
65
|
+
};
|
|
183
66
|
/**
|
|
184
|
-
*
|
|
67
|
+
* @description Server configuration options.
|
|
185
68
|
*/
|
|
186
|
-
type
|
|
187
|
-
[providerType: string]: Record<string, any>;
|
|
188
|
-
};
|
|
69
|
+
type MikroServeOptions = Partial<MikroServeConfiguration>;
|
|
189
70
|
/**
|
|
190
|
-
* Response utilities for handlers
|
|
71
|
+
* @description Response utilities for handlers.
|
|
191
72
|
*/
|
|
192
73
|
interface ResponseHelpers {
|
|
193
74
|
text(content: string, status?: number): HandlerResponse;
|
|
@@ -198,7 +79,7 @@ interface ResponseHelpers {
|
|
|
198
79
|
status(code: number): ResponseHelpers;
|
|
199
80
|
}
|
|
200
81
|
/**
|
|
201
|
-
* Context object passed to route handlers
|
|
82
|
+
* @description Context object passed to route handlers.
|
|
202
83
|
*/
|
|
203
84
|
interface Context extends ResponseHelpers {
|
|
204
85
|
req: http.IncomingMessage;
|
|
@@ -211,7 +92,7 @@ interface Context extends ResponseHelpers {
|
|
|
211
92
|
state: Record<string, any>;
|
|
212
93
|
}
|
|
213
94
|
/**
|
|
214
|
-
* Handler response object
|
|
95
|
+
* @description Handler response object.
|
|
215
96
|
*/
|
|
216
97
|
interface HandlerResponse {
|
|
217
98
|
statusCode: number;
|
|
@@ -219,15 +100,15 @@ interface HandlerResponse {
|
|
|
219
100
|
headers?: Record<string, string>;
|
|
220
101
|
}
|
|
221
102
|
/**
|
|
222
|
-
* Route handler function signature
|
|
103
|
+
* @description Route handler function signature.
|
|
223
104
|
*/
|
|
224
105
|
type RouteHandler = (context: Context) => Promise<HandlerResponse> | HandlerResponse;
|
|
225
106
|
/**
|
|
226
|
-
* Middleware function signature
|
|
107
|
+
* @description Middleware function signature.
|
|
227
108
|
*/
|
|
228
109
|
type Middleware = (context: Context, next: () => Promise<HandlerResponse>) => Promise<HandlerResponse> | HandlerResponse;
|
|
229
110
|
/**
|
|
230
|
-
* Route definition
|
|
111
|
+
* @description Route definition.
|
|
231
112
|
*/
|
|
232
113
|
interface Route {
|
|
233
114
|
method: string;
|
|
@@ -236,28 +117,11 @@ interface Route {
|
|
|
236
117
|
middlewares: Middleware[];
|
|
237
118
|
}
|
|
238
119
|
/**
|
|
239
|
-
* Path pattern parameter extraction
|
|
120
|
+
* @description Path pattern parameter extraction.
|
|
240
121
|
*/
|
|
241
122
|
interface PathPattern {
|
|
242
123
|
pattern: RegExp;
|
|
243
124
|
paramNames: string[];
|
|
244
125
|
}
|
|
245
|
-
/**
|
|
246
|
-
* Server configuration options
|
|
247
|
-
*/
|
|
248
|
-
interface MikroServeConfiguration {
|
|
249
|
-
port?: number;
|
|
250
|
-
host?: string;
|
|
251
|
-
useHttps?: boolean;
|
|
252
|
-
sslCert?: string;
|
|
253
|
-
sslKey?: string;
|
|
254
|
-
sslCa?: string;
|
|
255
|
-
debug?: boolean;
|
|
256
|
-
rateLimit?: {
|
|
257
|
-
requestsPerMinute: number;
|
|
258
|
-
enabled: boolean;
|
|
259
|
-
};
|
|
260
|
-
allowedDomains?: string[];
|
|
261
|
-
}
|
|
262
126
|
|
|
263
|
-
export type { Context,
|
|
127
|
+
export type { Context, HandlerResponse, Middleware, MikroServeConfiguration, MikroServeOptions, PathPattern, ResponseHelpers, Route, RouteHandler };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { MikroServeConfiguration } from '../interfaces/index.mjs';
|
|
2
|
+
import 'node:http';
|
|
3
|
+
|
|
4
|
+
declare const configDefaults: () => MikroServeConfiguration;
|
|
5
|
+
declare const getDefaultConfig: () => {
|
|
6
|
+
port: number;
|
|
7
|
+
host: string;
|
|
8
|
+
useHttps: boolean;
|
|
9
|
+
sslCert: string;
|
|
10
|
+
sslKey: string;
|
|
11
|
+
sslCa: string;
|
|
12
|
+
debug: boolean;
|
|
13
|
+
rateLimit: {
|
|
14
|
+
enabled: boolean;
|
|
15
|
+
requestsPerMinute: number;
|
|
16
|
+
};
|
|
17
|
+
allowedDomains: string[];
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export { configDefaults, getDefaultConfig };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { MikroServeConfiguration } from '../interfaces/index.js';
|
|
2
|
+
import 'node:http';
|
|
3
|
+
|
|
4
|
+
declare const configDefaults: () => MikroServeConfiguration;
|
|
5
|
+
declare const getDefaultConfig: () => {
|
|
6
|
+
port: number;
|
|
7
|
+
host: string;
|
|
8
|
+
useHttps: boolean;
|
|
9
|
+
sslCert: string;
|
|
10
|
+
sslKey: string;
|
|
11
|
+
sslCa: string;
|
|
12
|
+
debug: boolean;
|
|
13
|
+
rateLimit: {
|
|
14
|
+
enabled: boolean;
|
|
15
|
+
requestsPerMinute: number;
|
|
16
|
+
};
|
|
17
|
+
allowedDomains: string[];
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export { configDefaults, getDefaultConfig };
|