@boo-labs/server 0.0.0-stage → 1.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 +21 -0
- package/README.md +287 -2
- package/index.mjs +23 -0
- package/package.json +71 -4
- package/source/application/Kernel/index.mjs +1137 -0
- package/source/application/Server/index.mjs +1201 -0
- package/source/application/configurations/Http2CleartextServerConfiguration/index.mjs +168 -0
- package/source/application/configurations/Http2SecureServerConfiguration/index.mjs +172 -0
- package/source/application/configurations/HttpServerConfiguration/index.mjs +169 -0
- package/source/application/configurations/HttpsServerConfiguration/index.mjs +172 -0
- package/source/application/configurations/ServerConfiguration/Options/CORSOptions/CORSOptionsValue.mjs +158 -0
- package/source/application/configurations/ServerConfiguration/Options/CORSOptions/index.mjs +87 -0
- package/source/application/configurations/ServerConfiguration/Options/CSRFOptions/CSRFOptionsValue.mjs +178 -0
- package/source/application/configurations/ServerConfiguration/Options/CSRFOptions/index.mjs +80 -0
- package/source/application/configurations/ServerConfiguration/Options/CompressOptions/CompressOptionsValue.mjs +126 -0
- package/source/application/configurations/ServerConfiguration/Options/CompressOptions/index.mjs +81 -0
- package/source/application/configurations/ServerConfiguration/Options/CookieParserOptions/CookieParserOptionsValue.mjs +107 -0
- package/source/application/configurations/ServerConfiguration/Options/CookieParserOptions/index.mjs +82 -0
- package/source/application/configurations/ServerConfiguration/Options/CookieSessionOptions/CookieSessionOptionsValue.mjs +182 -0
- package/source/application/configurations/ServerConfiguration/Options/CookieSessionOptions/index.mjs +86 -0
- package/source/application/configurations/ServerConfiguration/Options/ListenOptions/ListenOptionsValue.mjs +95 -0
- package/source/application/configurations/ServerConfiguration/Options/ListenOptions/index.mjs +47 -0
- package/source/application/configurations/ServerConfiguration/Options/MiddlewareOption.mjs +102 -0
- package/source/application/configurations/ServerConfiguration/Options/Options.mjs +105 -0
- package/source/application/configurations/ServerConfiguration/Options/RateLimitOptions/RateLimitOptionsValue.mjs +164 -0
- package/source/application/configurations/ServerConfiguration/Options/RateLimitOptions/index.mjs +84 -0
- package/source/application/configurations/ServerConfiguration/Options/RequestOptions/RequestOptionsValue.mjs +108 -0
- package/source/application/configurations/ServerConfiguration/Options/RequestOptions/index.mjs +47 -0
- package/source/application/configurations/ServerConfiguration/Options/ResponseOptions/ResponseOptionsValue.mjs +101 -0
- package/source/application/configurations/ServerConfiguration/Options/ResponseOptions/index.mjs +47 -0
- package/source/application/configurations/ServerConfiguration/Options/SecurityHeadersOptions/SecurityHeadersOptionsValue.mjs +272 -0
- package/source/application/configurations/ServerConfiguration/Options/SecurityHeadersOptions/index.mjs +85 -0
- package/source/application/configurations/ServerConfiguration/Options/ServerOption.mjs +50 -0
- package/source/application/configurations/ServerConfiguration/Options/StaticOptions/StaticOptionsValue.mjs +164 -0
- package/source/application/configurations/ServerConfiguration/Options/StaticOptions/index.mjs +89 -0
- package/source/application/configurations/ServerConfiguration/index.mjs +781 -0
- package/source/application/resolvers/TransportResolver/index.mjs +119 -0
- package/source/application/use-cases/CloseServer/index.mjs +85 -0
- package/source/application/use-cases/ListenServer/index.mjs +98 -0
- package/source/core/EventSystem/index.mjs +110 -0
- package/source/core/Exchange/ExchangeContext.mjs +291 -0
- package/source/core/Exchange/Telemetry.mjs +193 -0
- package/source/core/Exchange/index.mjs +604 -0
- package/source/core/ExchangeLayerBuilder/index.mjs +133 -0
- package/source/core/IPCMain/IPCMain.mjs +507 -0
- package/source/core/IPCMain/IPCProtocol.mjs +441 -0
- package/source/core/IPCMain/IPCServerChannel.mjs +331 -0
- package/source/core/IPCMain/WebSocketAdapter.mjs +189 -0
- package/source/core/Request/BodyParser/BodyParser.mjs +197 -0
- package/source/core/Request/BodyParser/JSONParser.mjs +70 -0
- package/source/core/Request/BodyParser/MultipartParser.mjs +612 -0
- package/source/core/Request/BodyParser/URLEncodedParser.mjs +71 -0
- package/source/core/Request/RequestHeaders.mjs +177 -0
- package/source/core/Request/index.mjs +805 -0
- package/source/core/Response/ResponseHeaders.mjs +402 -0
- package/source/core/Response/index.mjs +1370 -0
- package/source/core/middlewares/CORSMiddleware/index.mjs +289 -0
- package/source/core/middlewares/CSRFMiddleware/index.mjs +284 -0
- package/source/core/middlewares/CompressMiddleware/index.mjs +460 -0
- package/source/core/middlewares/CookieParserMiddleware/index.mjs +194 -0
- package/source/core/middlewares/CookieSessionMiddleware/index.mjs +460 -0
- package/source/core/middlewares/RateLimitMiddleware/index.mjs +245 -0
- package/source/core/middlewares/SecurityHeadersMiddleware/index.mjs +151 -0
- package/source/core/middlewares/StaticMiddleware/index.mjs +628 -0
- package/source/core/routing/ExchangeLayer/ExchangeMatcher.mjs +127 -0
- package/source/core/routing/ExchangeLayer/index.mjs +254 -0
- package/source/core/routing/Pipeline/index.mjs +157 -0
- package/source/core/routing/Router/Route.mjs +184 -0
- package/source/core/routing/Router/index.mjs +523 -0
- package/source/core/routing/RouterRegister/OptionsMiddleware.mjs +147 -0
- package/source/core/routing/RouterRegister/index.mjs +150 -0
- package/source/core/routing/RouterSystem/index.mjs +225 -0
- package/source/core/value-objects/Address/index.mjs +281 -0
- package/source/core/value-objects/Endpoint/index.mjs +293 -0
- package/source/index.mjs +62 -0
- package/source/infrastructure/adapters/Http2Adapter/index.mjs +144 -0
- package/source/infrastructure/adapters/Http2CleartextAdapter/index.mjs +147 -0
- package/source/infrastructure/adapters/HttpAdapter/index.mjs +124 -0
- package/source/infrastructure/adapters/HttpsAdapter/index.mjs +124 -0
- package/source/infrastructure/adapters/TransportAdapter/createWebSocketOpenRequest.mjs +843 -0
- package/source/infrastructure/adapters/TransportAdapter/index.mjs +555 -0
- package/source/shared/Identifier/index.mjs +671 -0
- package/source/shared/constants/symbols/brands/index.mjs +45 -0
- package/source/shared/domain/UUIDV7/index.mjs +346 -0
- package/source/shared/errors/BaseError/index.mjs +157 -0
- package/source/shared/errors/IPCError/index.mjs +97 -0
- package/source/shared/errors/MiddlewareError/index.mjs +106 -0
- package/source/shared/errors/PathnamePatternError/index.mjs +103 -0
- package/source/shared/errors/RequestError/index.mjs +116 -0
- package/source/shared/errors/ResponseError/index.mjs +140 -0
- package/source/shared/errors/RouterError/index.mjs +90 -0
- package/source/shared/errors/ServerConfigurationError/index.mjs +551 -0
- package/source/shared/errors/ServerError/index.mjs +127 -0
- package/source/shared/errors/WebSocketError/index.mjs +58 -0
- package/source/shared/outcome/ErrorSchema.mjs +361 -0
- package/source/shared/outcome/Result/index.mjs +239 -0
- package/source/shared/outcome/Validation/index.mjs +208 -0
- package/source/shared/validations/Middleware/index.mjs +160 -0
- package/source/shared/validations/PathnamePattern/index.mjs +256 -0
- package/source/shared/validations/Server/NotFoundHandler/index.mjs +94 -0
- package/source/shared/validations/Server/Router/index.mjs +68 -0
- package/source/shared/validations/Server/ServerConfiguration/index.mjs +68 -0
- package/source/shared/validations/Server/SystemErrorHandler/index.mjs +94 -0
- package/source/shared/validations/ServerConfiguration/CORSOptions/index.mjs +310 -0
- package/source/shared/validations/ServerConfiguration/CSRFOptions/index.mjs +299 -0
- package/source/shared/validations/ServerConfiguration/CompressOptions/index.mjs +204 -0
- package/source/shared/validations/ServerConfiguration/CookieParserOptions/index.mjs +102 -0
- package/source/shared/validations/ServerConfiguration/CookieSessionOptions/index.mjs +332 -0
- package/source/shared/validations/ServerConfiguration/ListenOptions/index.mjs +178 -0
- package/source/shared/validations/ServerConfiguration/RateLimitOptions/index.mjs +229 -0
- package/source/shared/validations/ServerConfiguration/RequestOptions/index.mjs +132 -0
- package/source/shared/validations/ServerConfiguration/ResponseOptions/index.mjs +122 -0
- package/source/shared/validations/ServerConfiguration/SecurityHeadersOptions/index.mjs +137 -0
- package/source/shared/validations/ServerConfiguration/StaticOptions/index.mjs +248 -0
- package/types/index.d.ts +719 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Beltran Rodriguez Victor
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,288 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @boo-labs/server
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A lightweight, zero-dependency HTTP server for Node.js, designed around modular architecture, explicit configuration, and a predictable request lifecycle.
|
|
4
|
+
|
|
5
|
+
`@boo-labs/server` provides a small public API for building HTTP applications with support for HTTP/1.1, HTTPS, and HTTP/2, along with routing, middleware composition, lifecycle events, and graceful resource management.
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- **Zero runtime dependencies** — built on Node.js native APIs.
|
|
10
|
+
- **Multiple transports** — HTTP, HTTPS, HTTP/2 cleartext, and secure HTTP/2.
|
|
11
|
+
- **Composable routing** — organize endpoints with reusable routers.
|
|
12
|
+
- **Middleware pipeline** — process requests through ordered middleware.
|
|
13
|
+
- **Lifecycle events** — observe server and request-exchange activity.
|
|
14
|
+
- **Explicit resource management** — supports asynchronous disposal.
|
|
15
|
+
- **JavaScript-first implementation** — includes TypeScript declarations for consumers.
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install @boo-labs/server
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Imports
|
|
24
|
+
|
|
25
|
+
`@boo-labs/server` is an ECMAScript module (ESM).
|
|
26
|
+
|
|
27
|
+
```js
|
|
28
|
+
import Server, {
|
|
29
|
+
Router,
|
|
30
|
+
HttpServerConfiguration,
|
|
31
|
+
HttpsServerConfiguration,
|
|
32
|
+
Http2CleartextServerConfiguration,
|
|
33
|
+
Http2SecureServerConfiguration,
|
|
34
|
+
} from '@boo-labs/server';
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
TypeScript declarations for the public API are included in the package.
|
|
38
|
+
|
|
39
|
+
## Getting Started
|
|
40
|
+
|
|
41
|
+
```js
|
|
42
|
+
import Server, { HttpServerConfiguration } from '@boo-labs/server';
|
|
43
|
+
|
|
44
|
+
const configuration = new HttpServerConfiguration({
|
|
45
|
+
listen: {
|
|
46
|
+
host: '127.0.0.1',
|
|
47
|
+
port: 3000,
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
const server = new Server(configuration);
|
|
52
|
+
|
|
53
|
+
server.get('/hello', (exchange) => {
|
|
54
|
+
exchange.response.json({ message: 'Hello, World!' });
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
server.onListen(({ endpoint }) => {
|
|
58
|
+
console.log(`Server listening on ${endpoint.displayUrl}`);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
server.onError((error) => {
|
|
62
|
+
console.error('Server error:', error);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
await server.listen();
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Concepts
|
|
69
|
+
|
|
70
|
+
### Exchange
|
|
71
|
+
|
|
72
|
+
An `Exchange` represents a single HTTP transaction. It couples the incoming request with its outgoing response and exposes shared per-request state, correlation identifiers, and a cancellation signal.
|
|
73
|
+
|
|
74
|
+
Exchanges are created by the runtime and passed to middleware and handlers. Consumers do not construct exchanges.
|
|
75
|
+
|
|
76
|
+
```js
|
|
77
|
+
server.get('/hello', async (exchange) => {
|
|
78
|
+
exchange.response.json({ message: 'Hello, World!' });
|
|
79
|
+
});
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Key properties:
|
|
83
|
+
|
|
84
|
+
| Property | Type | Description |
|
|
85
|
+
|-------------|---------------------------|------------------------------------------|
|
|
86
|
+
| `id` | `string` | Unique identifier for the exchange. |
|
|
87
|
+
| `traceId` | `string` | W3C trace identifier. |
|
|
88
|
+
| `spanId` | `string` | W3C span identifier. |
|
|
89
|
+
| `signal` | `AbortSignal` | Cancellation signal for the exchange. |
|
|
90
|
+
| `request` | `Request` | Incoming request. |
|
|
91
|
+
| `response` | `Response` | Outgoing response. |
|
|
92
|
+
| `state` | `Record<string, unknown>` | Mutable per-request state. |
|
|
93
|
+
|
|
94
|
+
### Request
|
|
95
|
+
|
|
96
|
+
A transport-independent view of the incoming message. Exposes normalized
|
|
97
|
+
metadata and lazy body access via `request.body()`.
|
|
98
|
+
|
|
99
|
+
Supported media types for `body()`:
|
|
100
|
+
|
|
101
|
+
| Media type | Result |
|
|
102
|
+
|-------------------------------------|---------------------------------|
|
|
103
|
+
| `application/json` | Parsed JSON value |
|
|
104
|
+
| `application/*+json` | Parsed JSON value |
|
|
105
|
+
| `application/x-www-form-urlencoded` | Parsed key/value object |
|
|
106
|
+
| `multipart/form-data` | Parsed multipart representation |
|
|
107
|
+
|
|
108
|
+
Unsupported media types raise `RequestError`. When the body exceeds the configured limit, reading fails with `RequestError` and the connection may be closed without a normal error response.
|
|
109
|
+
|
|
110
|
+
The `CONNECT` method is not supported.
|
|
111
|
+
|
|
112
|
+
### Response
|
|
113
|
+
|
|
114
|
+
Built progressively by configuring status, headers, and body. Body methods do not send anything; only `end()` materializes and sends the response. A response can describe at most one body.
|
|
115
|
+
|
|
116
|
+
Convenience methods:
|
|
117
|
+
|
|
118
|
+
| Method | Purpose |
|
|
119
|
+
|--------------|--------------------------------------------------|
|
|
120
|
+
| `json()` | Serializes a value as JSON. |
|
|
121
|
+
| `html()` | Sends an HTML body. |
|
|
122
|
+
| `text()` | Sends a plain-text body. |
|
|
123
|
+
| `send()` | Sends a string or binary body. |
|
|
124
|
+
| `stream()` | Streams a readable body. |
|
|
125
|
+
| `redirect()` | Sends a redirect response. |
|
|
126
|
+
| `cache()` | Sets a public cache lifetime. |
|
|
127
|
+
| `noCache()` | Disables caching. |
|
|
128
|
+
| `vary()` | Adds fields to the `Vary` header. |
|
|
129
|
+
|
|
130
|
+
### Middleware
|
|
131
|
+
|
|
132
|
+
Middleware functions receive `(exchange, next)` and run in registration order. They may be registered globally, by pathname, on a route, or on a router.
|
|
133
|
+
|
|
134
|
+
```js
|
|
135
|
+
server.use(async (exchange, next) => {
|
|
136
|
+
// before
|
|
137
|
+
await next();
|
|
138
|
+
// after
|
|
139
|
+
});
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### Not Found and System Error Handling
|
|
143
|
+
|
|
144
|
+
- `server.notFound(handler)` — when no route matches (default: `404` JSON).
|
|
145
|
+
- `server.systemError(handler)` — when an error propagates (default: `500` JSON).
|
|
146
|
+
|
|
147
|
+
## Routing
|
|
148
|
+
|
|
149
|
+
Routes associate an HTTP method and a pathname pattern with middleware.
|
|
150
|
+
|
|
151
|
+
Supported methods:
|
|
152
|
+
|
|
153
|
+
| Method | Server | Router |
|
|
154
|
+
|------------|--------|--------|
|
|
155
|
+
| `get()` | ✅ | ✅ |
|
|
156
|
+
| `post()` | ✅ | ✅ |
|
|
157
|
+
| `put()` | ✅ | ✅ |
|
|
158
|
+
| `patch()` | ✅ | ✅ |
|
|
159
|
+
| `delete()` | ✅ | ✅ |
|
|
160
|
+
| `head()` | ✅ | ✅ |
|
|
161
|
+
| `trace()` | ✅ | ✅ |
|
|
162
|
+
| `query()` | ✅ | ✅ |
|
|
163
|
+
| `all()` | ❌ | ✅ |
|
|
164
|
+
|
|
165
|
+
**Note:** `OPTIONS` is handled automatically and does not require a dedicated registration method.
|
|
166
|
+
|
|
167
|
+
Pathname patterns support literals, named parameters (`:id` or `{id}`), and wildcards (`*` / trailing `/*`).
|
|
168
|
+
|
|
169
|
+
Named parameters and wildcards are used only for matching; captured values are not exposed on the exchange. To read a path segment, parse `exchange.request.pathname` directly.
|
|
170
|
+
|
|
171
|
+
```js
|
|
172
|
+
const api = new Router();
|
|
173
|
+
api.get('/users', listUsers);
|
|
174
|
+
server.mount('/api', api);
|
|
175
|
+
// Available at /api/users
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
## Server Configuration
|
|
179
|
+
|
|
180
|
+
Four configuration classes fix the transport:
|
|
181
|
+
|
|
182
|
+
| Class | Protocol | Transport |
|
|
183
|
+
|-------------------------------------|----------|-----------|
|
|
184
|
+
| `HttpServerConfiguration` | `http` | `h1` |
|
|
185
|
+
| `HttpsServerConfiguration` | `https` | `h1s` |
|
|
186
|
+
| `Http2CleartextServerConfiguration` | `http` | `h2c` |
|
|
187
|
+
| `Http2SecureServerConfiguration` | `https` | `h2` |
|
|
188
|
+
|
|
189
|
+
Common top-level options:
|
|
190
|
+
|
|
191
|
+
| Option | Purpose |
|
|
192
|
+
|-------------------|-----------------------------------------------|
|
|
193
|
+
| `connection` | Transport-specific Node.js server options. |
|
|
194
|
+
| `listen` | Host, port, and backlog for binding. |
|
|
195
|
+
| `request` | Request parsing and proxy trust. |
|
|
196
|
+
| `response` | Response shaping (ETag, charset). |
|
|
197
|
+
| `static` | Static file serving. |
|
|
198
|
+
| `cors` | Cross-Origin Resource Sharing. |
|
|
199
|
+
| `securityHeaders` | HTTP security response headers. |
|
|
200
|
+
| `rateLimit` | Request rate limiting. |
|
|
201
|
+
| `cookie` | Cookie parsing and cookie-backed sessions. |
|
|
202
|
+
| `csrf` | CSRF protection. |
|
|
203
|
+
| `compress` | Response compression. |
|
|
204
|
+
|
|
205
|
+
These options enable server features. When enabled, the corresponding behavior is applied before user-registered middleware.
|
|
206
|
+
|
|
207
|
+
See the [full API reference](https://github.com/vgbr-dev/boo-labs/wiki) for the complete option shapes and defaults.
|
|
208
|
+
|
|
209
|
+
## Lifecycle and Events
|
|
210
|
+
|
|
211
|
+
```js
|
|
212
|
+
await server.listen();
|
|
213
|
+
// ...
|
|
214
|
+
await server.close();
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
States:
|
|
218
|
+
|
|
219
|
+
| State | Description |
|
|
220
|
+
|-------------|------------------------------------------------------|
|
|
221
|
+
| `idle` | Initial state. The server has not started. |
|
|
222
|
+
| `starting` | The server is starting up. |
|
|
223
|
+
| `listening` | The server is accepting connections. |
|
|
224
|
+
| `stopping` | The server is shutting down. |
|
|
225
|
+
| `closed` | The server has closed. |
|
|
226
|
+
| `error` | The server encountered an error and cannot continue. |
|
|
227
|
+
|
|
228
|
+
Events:
|
|
229
|
+
|
|
230
|
+
| Event | Convenience method | Description |
|
|
231
|
+
|------------------|-----------------------|----------------------------------|
|
|
232
|
+
| `listen` | `onListen()` | The server started listening. |
|
|
233
|
+
| `close` | `onClose()` | The server has closed. |
|
|
234
|
+
| `error` | `onError()` | A server error occurred. |
|
|
235
|
+
| `exchange:start` | `onExchangeStart()` | An exchange began processing. |
|
|
236
|
+
| `exchange:end` | `onExchangeEnd()` | An exchange ended. |
|
|
237
|
+
| `exchange:error` | `onExchangeError()` | An exchange failed. |
|
|
238
|
+
|
|
239
|
+
`Server` implements `Symbol.asyncDispose` for `await using` when the runtime supports it.
|
|
240
|
+
|
|
241
|
+
## IPC
|
|
242
|
+
|
|
243
|
+
An IPC API over WebSocket at `/ipc`. Supports request-response channels (`handle` / invoke) and one-way events (`on` / event). Available while the
|
|
244
|
+
server is listening via `server.ipc`.
|
|
245
|
+
|
|
246
|
+
```js
|
|
247
|
+
await server.listen();
|
|
248
|
+
|
|
249
|
+
server.ipc.handle('users:get', async (id) => {
|
|
250
|
+
return usersRepository.findById(id);
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
server.ipc.on('analytics:event', (event) => {
|
|
254
|
+
analytics.record(event);
|
|
255
|
+
});
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
See the [full API reference](https://github.com/vgbr-dev/boo-labs/wiki) for the wire protocol and handler details.
|
|
259
|
+
|
|
260
|
+
## Errors
|
|
261
|
+
|
|
262
|
+
Public APIs throw errors that extend `Error` and expose a stable `code`
|
|
263
|
+
property.
|
|
264
|
+
|
|
265
|
+
| Error | Domain |
|
|
266
|
+
|----------------------------|----------------------------------------------|
|
|
267
|
+
| `ServerConfigurationError` | Server configuration validation. |
|
|
268
|
+
| `RequestError` | Incoming request processing. |
|
|
269
|
+
| `ResponseError` | Outgoing response construction. |
|
|
270
|
+
| `RouterError` | Router route registration. |
|
|
271
|
+
| `PathnamePatternError` | Pathname pattern validation. |
|
|
272
|
+
| `MiddlewareError` | Middleware validation. |
|
|
273
|
+
| `ServerError` | Server lifecycle and state transitions. |
|
|
274
|
+
| `IPCError` | IPC operations. |
|
|
275
|
+
|
|
276
|
+
Error codes are documented in the [project wiki](https://github.com/vgbr-dev/boo-labs/wiki/Errors).
|
|
277
|
+
|
|
278
|
+
## Documentation
|
|
279
|
+
|
|
280
|
+
- [Full API reference](https://github.com/vgbr-dev/boo-labs/wiki) — complete public API, configuration options, response methods, IPC protocol, and more.
|
|
281
|
+
|
|
282
|
+
## License
|
|
283
|
+
|
|
284
|
+
Distributed under the MIT License. See the [LICENSE](./LICENSE) file for details.
|
|
285
|
+
|
|
286
|
+
## Dedication
|
|
287
|
+
|
|
288
|
+
This project is named after my sister — "Boo". Her nickname gave this project its name.
|
package/index.mjs
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
/**
|
|
3
|
+
* @file Entry point for `ES Module` consumers.
|
|
4
|
+
*
|
|
5
|
+
* @description Provides the default export and named exports of the
|
|
6
|
+
* `@boo/server` public API for modern JavaScript environments using ES Modules.
|
|
7
|
+
*
|
|
8
|
+
* This file acts as a facade, re-exporting the main functionality from the
|
|
9
|
+
* internal source module while maintaining a clean public boundary.
|
|
10
|
+
*
|
|
11
|
+
* @module @boo/server/esm
|
|
12
|
+
* @since 1.0.0
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
// ━━ EXPORT MODULE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
16
|
+
export {
|
|
17
|
+
default,
|
|
18
|
+
Router,
|
|
19
|
+
HttpServerConfiguration,
|
|
20
|
+
HttpsServerConfiguration,
|
|
21
|
+
Http2CleartextServerConfiguration,
|
|
22
|
+
Http2SecureServerConfiguration,
|
|
23
|
+
} from './source/index.mjs';
|
package/package.json
CHANGED
|
@@ -1,6 +1,73 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@boo-labs/server",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "A zero-dependency, frameworkless HTTP server for Node.js, built around Clean Architecture principles.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"http-server",
|
|
7
|
+
"nodejs",
|
|
8
|
+
"zero-dependency",
|
|
9
|
+
"frameworkless",
|
|
10
|
+
"esm",
|
|
11
|
+
"router",
|
|
12
|
+
"middleware",
|
|
13
|
+
"clean-architecture"
|
|
14
|
+
],
|
|
15
|
+
"homepage": "https://github.com/vgbr-dev/boo-labs#readme",
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "https://github.com/vgbr-dev/boo-labs/issues"
|
|
18
|
+
},
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/vgbr-dev/boo-labs.git",
|
|
22
|
+
"directory": "packages/server"
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"source",
|
|
26
|
+
"types",
|
|
27
|
+
"index.mjs",
|
|
28
|
+
"README.md",
|
|
29
|
+
"LICENSE"
|
|
30
|
+
],
|
|
31
|
+
"author": {
|
|
32
|
+
"name": "Victor Giovanni Beltrán Rodríguez",
|
|
33
|
+
"email": "vgbr.dev@gmail.com",
|
|
34
|
+
"url": "https://vgbr-dev.blogspot.com"
|
|
35
|
+
},
|
|
36
|
+
"type": "module",
|
|
37
|
+
"license": "MIT",
|
|
38
|
+
"types": "./types/index.d.ts",
|
|
39
|
+
"exports": {
|
|
40
|
+
".": {
|
|
41
|
+
"types": "./types/index.d.ts",
|
|
42
|
+
"import": "./index.mjs",
|
|
43
|
+
"default": "./index.mjs"
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
"imports": {
|
|
47
|
+
"#Server": "./source/application/Server/index.mjs",
|
|
48
|
+
"#Kernel": "./source/application/Kernel/index.mjs",
|
|
49
|
+
"#Exchange": "./source/core/Exchange/index.mjs",
|
|
50
|
+
"#IPCMain": "./source/core/IPCMain/IPCMain.mjs",
|
|
51
|
+
"#ServerOptions/*": "./source/application/configurations/ServerConfiguration/Options/*/index.mjs",
|
|
52
|
+
"#configurations/*": "./source/application/configurations/*/index.mjs",
|
|
53
|
+
"#Request": "./source/core/Request/index.mjs",
|
|
54
|
+
"#Response": "./source/core/Response/index.mjs",
|
|
55
|
+
"#use-cases/*": "./source/application/use-cases/*/index.mjs",
|
|
56
|
+
"#value-objects/*": "./source/core/value-objects/*/index.mjs",
|
|
57
|
+
"#adapters/*": "./source/infrastructure/adapters/*/index.mjs",
|
|
58
|
+
"#resolvers/*": "./source/application/resolvers/*/index.mjs",
|
|
59
|
+
"#routing/*": "./source/core/routing/*/index.mjs",
|
|
60
|
+
"#ExchangeLayerBuilder": "./source/core/ExchangeLayerBuilder/index.mjs",
|
|
61
|
+
"#middlewares/*": "./source/core/middlewares/*/index.mjs",
|
|
62
|
+
"#EventSystem": "./source/core/EventSystem/index.mjs",
|
|
63
|
+
"#shared/*": "./source/shared/*/index.mjs"
|
|
64
|
+
},
|
|
65
|
+
"scripts": {
|
|
66
|
+
"test": "node --env-file=.env.test --test test/**/*.test.mjs",
|
|
67
|
+
"lint": "eslint .",
|
|
68
|
+
"prepublishOnly": "npm test"
|
|
69
|
+
},
|
|
70
|
+
"engines": {
|
|
71
|
+
"node": ">=22"
|
|
72
|
+
}
|
|
73
|
+
}
|