barehttp 2.2.0 → 2.3.0

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/lib/server.d.ts CHANGED
@@ -7,6 +7,7 @@ import { HttpMethodsUnion, StatusCodesUnion } from './utils/index.js';
7
7
  import { CorsOptions } from './middlewares/cors/cors.js';
8
8
  import { WebSocketServer } from './websocket.js';
9
9
  import { Server } from 'http';
10
+ import { ServerOptions as ServerHTTPSOptions } from 'https';
10
11
  type Middleware = (flow: BareRequest) => Promise<void> | void;
11
12
  type Handler<H extends {
12
13
  [key: string]: string | undefined;
@@ -94,6 +95,10 @@ type BareOptions<A extends IP> = {
94
95
  * Enable Cors
95
96
  */
96
97
  cors?: boolean | CorsOptions;
98
+ /**
99
+ * Custom HTTPS options for the server
100
+ */
101
+ httpsOptions?: ServerHTTPSOptions;
97
102
  };
98
103
  type ExtractRouteParams<T extends string> = T extends `${string}:${infer Param}/${infer Rest}` ? {
99
104
  [K in Param | keyof ExtractRouteParams<Rest>]: string;
package/lib/server.js CHANGED
@@ -9,6 +9,7 @@ import { WebSocketServer } from './websocket.js';
9
9
  import { generateRouteSchema } from './schemas/generator.js';
10
10
  import dns from 'dns';
11
11
  import { createServer } from 'http';
12
+ import { createServer as createServerHTTPS } from 'https';
12
13
  export class BareServer {
13
14
  bareOptions;
14
15
  server;
@@ -29,7 +30,12 @@ export class BareServer {
29
30
  constructor(bareOptions = {}) {
30
31
  this.bareOptions = bareOptions;
31
32
  // init
32
- this.server = createServer(this.#listener.bind(this));
33
+ if (bareOptions.httpsOptions) {
34
+ this.server = createServerHTTPS(bareOptions.httpsOptions, this.#onRequest);
35
+ }
36
+ else {
37
+ this.server = createServer(this.#onRequest);
38
+ }
33
39
  this.attachGracefulHandlers();
34
40
  this.attachRoutesDeclarator();
35
41
  this.applyLaunchOptions();
@@ -55,6 +61,7 @@ export class BareServer {
55
61
  this.#router.lookup(flow._originalRequest, flow._originalResponse);
56
62
  });
57
63
  };
64
+ #onRequest = this.#listener.bind(this);
58
65
  /**
59
66
  * This function generates previously defined middlewares for the sequential execution
60
67
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "barehttp",
3
- "version": "2.2.0",
3
+ "version": "2.3.0",
4
4
  "description": "Lightweight and fast Node.js web server",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",