mikroserve 0.0.1

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,7 @@
1
+ Copyright 2025-present Mikael Vesavuori
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # MikroServe
2
+
3
+ TODO
@@ -0,0 +1,106 @@
1
+ import http from 'node:http';
2
+ import https from 'node:https';
3
+ import { MikroServeConfiguration, Middleware, RouteHandler } from './interfaces/index.mjs';
4
+
5
+ /**
6
+ * MikroServe manages HTTP server operations with routing.
7
+ */
8
+ declare class MikroServe {
9
+ private config;
10
+ private rateLimiter;
11
+ private router;
12
+ private useHttps;
13
+ private sslCert?;
14
+ private sslKey?;
15
+ private sslCa?;
16
+ private debug;
17
+ /**
18
+ * @description Creates a new MikroServe instance.
19
+ * @param config - Server configuration options
20
+ */
21
+ constructor(config: MikroServeConfiguration);
22
+ /**
23
+ * Register a global middleware
24
+ */
25
+ use(middleware: Middleware): this;
26
+ /**
27
+ * Register a GET route
28
+ */
29
+ get(path: string, ...handlers: (RouteHandler | Middleware)[]): this;
30
+ /**
31
+ * Register a POST route
32
+ */
33
+ post(path: string, ...handlers: (RouteHandler | Middleware)[]): this;
34
+ /**
35
+ * Register a PUT route
36
+ */
37
+ put(path: string, ...handlers: (RouteHandler | Middleware)[]): this;
38
+ /**
39
+ * Register a DELETE route
40
+ */
41
+ delete(path: string, ...handlers: (RouteHandler | Middleware)[]): this;
42
+ /**
43
+ * Register a PATCH route
44
+ */
45
+ patch(path: string, ...handlers: (RouteHandler | Middleware)[]): this;
46
+ /**
47
+ * Register an OPTIONS route
48
+ */
49
+ options(path: string, ...handlers: (RouteHandler | Middleware)[]): this;
50
+ /**
51
+ * Creates an HTTP/HTTPS server, sets up graceful shutdown, and starts listening.
52
+ * @returns Running HTTP/HTTPS server
53
+ */
54
+ start(): http.Server | https.Server;
55
+ /**
56
+ * Creates and configures a server instance without starting it.
57
+ * @returns Configured HTTP or HTTPS server instance
58
+ */
59
+ createServer(): http.Server | https.Server;
60
+ /**
61
+ * Rate limiting middleware
62
+ */
63
+ private rateLimitMiddleware;
64
+ /**
65
+ * Request handler for HTTP and HTTPS servers.
66
+ */
67
+ private requestHandler;
68
+ /**
69
+ * Writes out a clean log to represent the duration of the request.
70
+ */
71
+ private logDuration;
72
+ /**
73
+ * Parses the request body based on content type.
74
+ * @param req - HTTP request object
75
+ * @returns Promise resolving to the parsed body
76
+ * @throws Will throw if body cannot be parsed
77
+ */
78
+ /**
79
+ * Parses the request body based on content type.
80
+ * @param req - HTTP request object
81
+ * @returns Promise resolving to the parsed body
82
+ * @throws Will throw if body cannot be parsed
83
+ */
84
+ private parseBody;
85
+ /**
86
+ * CORS middleware
87
+ */
88
+ private setCorsHeaders;
89
+ /**
90
+ * Set security headers
91
+ */
92
+ private setSecurityHeaders;
93
+ /**
94
+ * Sends a response with appropriate headers.
95
+ * @param res - HTTP response object
96
+ * @param response - Response data and status code
97
+ */
98
+ private respond;
99
+ /**
100
+ * Sets up graceful shutdown handlers for a server.
101
+ * @param server - The HTTP/HTTPS server to add shutdown handlers to
102
+ */
103
+ setupGracefulShutdown(server: http.Server | https.Server): void;
104
+ }
105
+
106
+ export { MikroServe };
@@ -0,0 +1,106 @@
1
+ import http from 'node:http';
2
+ import https from 'node:https';
3
+ import { MikroServeConfiguration, Middleware, RouteHandler } from './interfaces/index.js';
4
+
5
+ /**
6
+ * MikroServe manages HTTP server operations with routing.
7
+ */
8
+ declare class MikroServe {
9
+ private config;
10
+ private rateLimiter;
11
+ private router;
12
+ private useHttps;
13
+ private sslCert?;
14
+ private sslKey?;
15
+ private sslCa?;
16
+ private debug;
17
+ /**
18
+ * @description Creates a new MikroServe instance.
19
+ * @param config - Server configuration options
20
+ */
21
+ constructor(config: MikroServeConfiguration);
22
+ /**
23
+ * Register a global middleware
24
+ */
25
+ use(middleware: Middleware): this;
26
+ /**
27
+ * Register a GET route
28
+ */
29
+ get(path: string, ...handlers: (RouteHandler | Middleware)[]): this;
30
+ /**
31
+ * Register a POST route
32
+ */
33
+ post(path: string, ...handlers: (RouteHandler | Middleware)[]): this;
34
+ /**
35
+ * Register a PUT route
36
+ */
37
+ put(path: string, ...handlers: (RouteHandler | Middleware)[]): this;
38
+ /**
39
+ * Register a DELETE route
40
+ */
41
+ delete(path: string, ...handlers: (RouteHandler | Middleware)[]): this;
42
+ /**
43
+ * Register a PATCH route
44
+ */
45
+ patch(path: string, ...handlers: (RouteHandler | Middleware)[]): this;
46
+ /**
47
+ * Register an OPTIONS route
48
+ */
49
+ options(path: string, ...handlers: (RouteHandler | Middleware)[]): this;
50
+ /**
51
+ * Creates an HTTP/HTTPS server, sets up graceful shutdown, and starts listening.
52
+ * @returns Running HTTP/HTTPS server
53
+ */
54
+ start(): http.Server | https.Server;
55
+ /**
56
+ * Creates and configures a server instance without starting it.
57
+ * @returns Configured HTTP or HTTPS server instance
58
+ */
59
+ createServer(): http.Server | https.Server;
60
+ /**
61
+ * Rate limiting middleware
62
+ */
63
+ private rateLimitMiddleware;
64
+ /**
65
+ * Request handler for HTTP and HTTPS servers.
66
+ */
67
+ private requestHandler;
68
+ /**
69
+ * Writes out a clean log to represent the duration of the request.
70
+ */
71
+ private logDuration;
72
+ /**
73
+ * Parses the request body based on content type.
74
+ * @param req - HTTP request object
75
+ * @returns Promise resolving to the parsed body
76
+ * @throws Will throw if body cannot be parsed
77
+ */
78
+ /**
79
+ * Parses the request body based on content type.
80
+ * @param req - HTTP request object
81
+ * @returns Promise resolving to the parsed body
82
+ * @throws Will throw if body cannot be parsed
83
+ */
84
+ private parseBody;
85
+ /**
86
+ * CORS middleware
87
+ */
88
+ private setCorsHeaders;
89
+ /**
90
+ * Set security headers
91
+ */
92
+ private setSecurityHeaders;
93
+ /**
94
+ * Sends a response with appropriate headers.
95
+ * @param res - HTTP response object
96
+ * @param response - Response data and status code
97
+ */
98
+ private respond;
99
+ /**
100
+ * Sets up graceful shutdown handlers for a server.
101
+ * @param server - The HTTP/HTTPS server to add shutdown handlers to
102
+ */
103
+ setupGracefulShutdown(server: http.Server | https.Server): void;
104
+ }
105
+
106
+ export { MikroServe };