mikroserve 0.0.4 → 0.0.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/README.md CHANGED
@@ -13,7 +13,7 @@
13
13
  - Supports custom middlewares
14
14
  - Out-of-the-box CORS support
15
15
  - Built-in customizable rate limiter
16
- - Tiny (~3.2kb gzipped)
16
+ - Tiny (~4.9kb gzipped)
17
17
  - Only a single dependency: [MikroConf](https://github.com/mikaelvesavuori/mikroconf)
18
18
 
19
19
  ## Installation
@@ -46,22 +46,23 @@ api.start();
46
46
  // The response should be "Hello world!"
47
47
  ```
48
48
 
49
- ## Bigger example
49
+ ### Bigger example
50
50
 
51
51
  ```typescript
52
52
  import { MikroServe } from 'mikroserve';
53
53
 
54
- // Create a new api instance
54
+ // Create a new API instance
55
55
  const api = new MikroServe({
56
+ // These are the default values
56
57
  port: 3000,
57
58
  host: '0.0.0.0',
58
59
  useHttps: false,
59
60
  sslCert: '',
60
61
  sslKey: '',
61
62
  sslCa: '',
62
- debug: true,
63
+ debug: false,
63
64
  rateLimit: {
64
- requestsPerMinute: 60,
65
+ requestsPerMinute: 100,
65
66
  enabled: true
66
67
  },
67
68
  allowedDomains: ['*']
@@ -165,6 +166,42 @@ api.get('/error', () => {
165
166
  api.start();
166
167
  ```
167
168
 
169
+ ## Configuration
170
+
171
+ All of the settings already presented in the above examples can be provided in multiple ways.
172
+
173
+ - They can be provided via the CLI, e.g. `node app.js --port 1234`.
174
+ - Certain values can be provided via environment variables.
175
+ - Port: `process.env.PORT` - number
176
+ - Host: `process.env.HOST` - string
177
+ - Debug: `process.env.DEBUG` - boolean
178
+ - Programmatically/directly via scripting, e.g. `new MikroServe({ port: 1234 })`.
179
+ - They can be placed in a configuration file named `mikroserve.config.json` (plain JSON), which will be automatically applied on load.
180
+
181
+ ### Options
182
+
183
+ | CLI argument | CLI value | JSON (config file) value | Environment variable |
184
+ |--------------|-----------------------------|-----------------------------|----------------------|
185
+ | --port | `<number>` | port | PORT |
186
+ | --host | `<string>` | host | HOST |
187
+ | --https | none (is flag) | useHttps | |
188
+ | --cert | `<string>` | sslCert | |
189
+ | --key | `<string>` | sslKey | |
190
+ | --ca | `<string>` | sslCa | |
191
+ | --debug | none (is flag) | debug | DEBUG |
192
+ | --ratelimit | none (is flag) | rateLimit.enabled | |
193
+ | --rps | `<number>` | rateLimit.requestsPerMinute | |
194
+ | --allowed | `<comma-separated strings>` | allowedDomains | |
195
+
196
+ ### Order of application
197
+
198
+ As per [MikroConf](https://github.com/mikaelvesavuori/mikroconf) behavior, the configuration sources are applied in this order:
199
+
200
+ 1. Command line arguments (highest priority)
201
+ 2. Programmatically provided config
202
+ 3. Config file (JSON)
203
+ 4. Default values (lowest priority)
204
+
168
205
  ## Create self-signed HTTPS certificates
169
206
 
170
207
  On Mac and Linux, run:
@@ -6,9 +6,9 @@ import { MikroServeOptions, Middleware, RouteHandler } from './interfaces/index.
6
6
  * @description MikroServe manages HTTP server operations with routing.
7
7
  */
8
8
  declare class MikroServe {
9
+ private config;
9
10
  private rateLimiter;
10
11
  private router;
11
- private config;
12
12
  /**
13
13
  * @description Creates a new MikroServe instance.
14
14
  */
@@ -6,9 +6,9 @@ import { MikroServeOptions, Middleware, RouteHandler } from './interfaces/index.
6
6
  * @description MikroServe manages HTTP server operations with routing.
7
7
  */
8
8
  declare class MikroServe {
9
+ private config;
9
10
  private rateLimiter;
10
11
  private router;
11
- private config;
12
12
  /**
13
13
  * @description Creates a new MikroServe instance.
14
14
  */
package/lib/MikroServe.js CHANGED
@@ -281,8 +281,8 @@ var Router = class {
281
281
  }
282
282
  };
283
283
 
284
- // src/utils/getTruthyEnvValue.ts
285
- function getTruthyEnvValue(value) {
284
+ // src/utils/getTruthyValue.ts
285
+ function getTruthyValue(value) {
286
286
  if (value === "true" || value === true) return true;
287
287
  return false;
288
288
  }
@@ -296,7 +296,7 @@ var configDefaults = () => {
296
296
  sslCert: "",
297
297
  sslKey: "",
298
298
  sslCa: "",
299
- debug: getTruthyEnvValue(process.env.DEBUG) || false,
299
+ debug: getTruthyValue(process.env.DEBUG) || false,
300
300
  rateLimit: {
301
301
  enabled: true,
302
302
  requestsPerMinute: 100
@@ -307,9 +307,9 @@ var configDefaults = () => {
307
307
 
308
308
  // src/MikroServe.ts
309
309
  var MikroServe = class {
310
+ config;
310
311
  rateLimiter;
311
312
  router;
312
- config;
313
313
  /**
314
314
  * @description Creates a new MikroServe instance.
315
315
  */
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  MikroServe
3
- } from "./chunk-6UXWR6LD.mjs";
3
+ } from "./chunk-BUKLE4JV.mjs";
4
4
  import "./chunk-ZFBBESGU.mjs";
5
5
  import "./chunk-KJT4SET2.mjs";
6
- import "./chunk-RP67R3W4.mjs";
7
- import "./chunk-CQPU7577.mjs";
6
+ import "./chunk-NSHBEU32.mjs";
7
+ import "./chunk-6HESV5Q6.mjs";
8
8
  export {
9
9
  MikroServe
10
10
  };
@@ -0,0 +1,9 @@
1
+ // src/utils/getTruthyValue.ts
2
+ function getTruthyValue(value) {
3
+ if (value === "true" || value === true) return true;
4
+ return false;
5
+ }
6
+
7
+ export {
8
+ getTruthyValue
9
+ };
@@ -6,7 +6,7 @@ import {
6
6
  } from "./chunk-KJT4SET2.mjs";
7
7
  import {
8
8
  configDefaults
9
- } from "./chunk-RP67R3W4.mjs";
9
+ } from "./chunk-NSHBEU32.mjs";
10
10
 
11
11
  // src/MikroServe.ts
12
12
  import { readFileSync } from "node:fs";
@@ -14,9 +14,9 @@ import http from "node:http";
14
14
  import https from "node:https";
15
15
  import { MikroConf, parsers } from "mikroconf";
16
16
  var MikroServe = class {
17
+ config;
17
18
  rateLimiter;
18
19
  router;
19
- config;
20
20
  /**
21
21
  * @description Creates a new MikroServe instance.
22
22
  */
@@ -1,6 +1,6 @@
1
1
  import {
2
- getTruthyEnvValue
3
- } from "./chunk-CQPU7577.mjs";
2
+ getTruthyValue
3
+ } from "./chunk-6HESV5Q6.mjs";
4
4
 
5
5
  // src/utils/configDefaults.ts
6
6
  var configDefaults = () => {
@@ -11,7 +11,7 @@ var configDefaults = () => {
11
11
  sslCert: "",
12
12
  sslKey: "",
13
13
  sslCa: "",
14
- debug: getTruthyEnvValue(process.env.DEBUG) || false,
14
+ debug: getTruthyValue(process.env.DEBUG) || false,
15
15
  rateLimit: {
16
16
  enabled: true,
17
17
  requestsPerMinute: 100
package/lib/index.d.mts CHANGED
@@ -1,4 +1,3 @@
1
- #!/usr/bin/env node
2
1
  export { MikroServe } from './MikroServe.mjs';
3
2
  export { Context } from './interfaces/index.mjs';
4
3
  import 'node:http';
package/lib/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- #!/usr/bin/env node
2
1
  export { MikroServe } from './MikroServe.js';
3
2
  export { Context } from './interfaces/index.js';
4
3
  import 'node:http';
package/lib/index.js CHANGED
@@ -1,4 +1,3 @@
1
- #!/usr/bin/env node
2
1
  "use strict";
3
2
  var __create = Object.create;
4
3
  var __defProp = Object.defineProperty;
@@ -284,8 +283,8 @@ var Router = class {
284
283
  }
285
284
  };
286
285
 
287
- // src/utils/getTruthyEnvValue.ts
288
- function getTruthyEnvValue(value) {
286
+ // src/utils/getTruthyValue.ts
287
+ function getTruthyValue(value) {
289
288
  if (value === "true" || value === true) return true;
290
289
  return false;
291
290
  }
@@ -299,7 +298,7 @@ var configDefaults = () => {
299
298
  sslCert: "",
300
299
  sslKey: "",
301
300
  sslCa: "",
302
- debug: getTruthyEnvValue(process.env.DEBUG) || false,
301
+ debug: getTruthyValue(process.env.DEBUG) || false,
303
302
  rateLimit: {
304
303
  enabled: true,
305
304
  requestsPerMinute: 100
@@ -310,9 +309,9 @@ var configDefaults = () => {
310
309
 
311
310
  // src/MikroServe.ts
312
311
  var MikroServe = class {
312
+ config;
313
313
  rateLimiter;
314
314
  router;
315
- config;
316
315
  /**
317
316
  * @description Creates a new MikroServe instance.
318
317
  */
@@ -642,21 +641,6 @@ var MikroServe = class {
642
641
  process.on("unhandledRejection", shutdown);
643
642
  }
644
643
  };
645
-
646
- // src/index.ts
647
- async function main() {
648
- const isRunFromCommandLine = process.argv[1]?.includes("node_modules/.bin/mikroserve");
649
- const force = process.argv[1]?.includes("mikroauth/src/index.ts") && (process.argv[2] || "") === "--force";
650
- if (isRunFromCommandLine || force && isRunFromCommandLine) {
651
- console.log("\u{1F680} Welcome to MikroServe! \u2728");
652
- try {
653
- new MikroServe();
654
- } catch (error) {
655
- console.error(error);
656
- }
657
- }
658
- }
659
- main();
660
644
  // Annotate the CommonJS export names for ESM import in node:
661
645
  0 && (module.exports = {
662
646
  MikroServe
package/lib/index.mjs CHANGED
@@ -1,26 +1,10 @@
1
- #!/usr/bin/env node
2
1
  import {
3
2
  MikroServe
4
- } from "./chunk-6UXWR6LD.mjs";
3
+ } from "./chunk-BUKLE4JV.mjs";
5
4
  import "./chunk-ZFBBESGU.mjs";
6
5
  import "./chunk-KJT4SET2.mjs";
7
- import "./chunk-RP67R3W4.mjs";
8
- import "./chunk-CQPU7577.mjs";
9
-
10
- // src/index.ts
11
- async function main() {
12
- const isRunFromCommandLine = process.argv[1]?.includes("node_modules/.bin/mikroserve");
13
- const force = process.argv[1]?.includes("mikroauth/src/index.ts") && (process.argv[2] || "") === "--force";
14
- if (isRunFromCommandLine || force && isRunFromCommandLine) {
15
- console.log("\u{1F680} Welcome to MikroServe! \u2728");
16
- try {
17
- new MikroServe();
18
- } catch (error) {
19
- console.error(error);
20
- }
21
- }
22
- }
23
- main();
6
+ import "./chunk-NSHBEU32.mjs";
7
+ import "./chunk-6HESV5Q6.mjs";
24
8
  export {
25
9
  MikroServe
26
10
  };
@@ -25,8 +25,8 @@ __export(configDefaults_exports, {
25
25
  });
26
26
  module.exports = __toCommonJS(configDefaults_exports);
27
27
 
28
- // src/utils/getTruthyEnvValue.ts
29
- function getTruthyEnvValue(value) {
28
+ // src/utils/getTruthyValue.ts
29
+ function getTruthyValue(value) {
30
30
  if (value === "true" || value === true) return true;
31
31
  return false;
32
32
  }
@@ -40,7 +40,7 @@ var configDefaults = () => {
40
40
  sslCert: "",
41
41
  sslKey: "",
42
42
  sslCa: "",
43
- debug: getTruthyEnvValue(process.env.DEBUG) || false,
43
+ debug: getTruthyValue(process.env.DEBUG) || false,
44
44
  rateLimit: {
45
45
  enabled: true,
46
46
  requestsPerMinute: 100
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  configDefaults,
3
3
  getDefaultConfig
4
- } from "../chunk-RP67R3W4.mjs";
5
- import "../chunk-CQPU7577.mjs";
4
+ } from "../chunk-NSHBEU32.mjs";
5
+ import "../chunk-6HESV5Q6.mjs";
6
6
  export {
7
7
  configDefaults,
8
8
  getDefaultConfig
@@ -0,0 +1,6 @@
1
+ /**
2
+ * @description Check if a value is a boolean or stringly "true".
3
+ */
4
+ declare function getTruthyValue(value: string | boolean | undefined): boolean;
5
+
6
+ export { getTruthyValue };
@@ -0,0 +1,6 @@
1
+ /**
2
+ * @description Check if a value is a boolean or stringly "true".
3
+ */
4
+ declare function getTruthyValue(value: string | boolean | undefined): boolean;
5
+
6
+ export { getTruthyValue };
@@ -17,17 +17,17 @@ var __copyProps = (to, from, except, desc) => {
17
17
  };
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
 
20
- // src/utils/getTruthyEnvValue.ts
21
- var getTruthyEnvValue_exports = {};
22
- __export(getTruthyEnvValue_exports, {
23
- getTruthyEnvValue: () => getTruthyEnvValue
20
+ // src/utils/getTruthyValue.ts
21
+ var getTruthyValue_exports = {};
22
+ __export(getTruthyValue_exports, {
23
+ getTruthyValue: () => getTruthyValue
24
24
  });
25
- module.exports = __toCommonJS(getTruthyEnvValue_exports);
26
- function getTruthyEnvValue(value) {
25
+ module.exports = __toCommonJS(getTruthyValue_exports);
26
+ function getTruthyValue(value) {
27
27
  if (value === "true" || value === true) return true;
28
28
  return false;
29
29
  }
30
30
  // Annotate the CommonJS export names for ESM import in node:
31
31
  0 && (module.exports = {
32
- getTruthyEnvValue
32
+ getTruthyValue
33
33
  });
@@ -0,0 +1,6 @@
1
+ import {
2
+ getTruthyValue
3
+ } from "../chunk-6HESV5Q6.mjs";
4
+ export {
5
+ getTruthyValue
6
+ };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mikroserve",
3
3
  "description": "Minimalistic, ready-to-use API, built on Node.js primitives.",
4
- "version": "0.0.4",
4
+ "version": "0.0.5",
5
5
  "author": "Mikael Vesavuori",
6
6
  "license": "MIT",
7
7
  "keywords": [],
@@ -1,9 +0,0 @@
1
- // src/utils/getTruthyEnvValue.ts
2
- function getTruthyEnvValue(value) {
3
- if (value === "true" || value === true) return true;
4
- return false;
5
- }
6
-
7
- export {
8
- getTruthyEnvValue
9
- };
@@ -1,6 +0,0 @@
1
- /**
2
- * @description TODO
3
- */
4
- declare function getTruthyEnvValue(value: string | boolean | undefined): boolean;
5
-
6
- export { getTruthyEnvValue };
@@ -1,6 +0,0 @@
1
- /**
2
- * @description TODO
3
- */
4
- declare function getTruthyEnvValue(value: string | boolean | undefined): boolean;
5
-
6
- export { getTruthyEnvValue };
@@ -1,6 +0,0 @@
1
- import {
2
- getTruthyEnvValue
3
- } from "../chunk-CQPU7577.mjs";
4
- export {
5
- getTruthyEnvValue
6
- };