miqro 6.2.0 → 6.2.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.
@@ -1,3 +1,4 @@
1
+ import { ServerOptions } from "node:https";
1
2
  interface MiqroJSON {
2
3
  services?: string[];
3
4
  port?: string | number;
@@ -6,6 +7,9 @@ interface MiqroJSON {
6
7
  browser?: string | boolean;
7
8
  logFile?: string | boolean;
8
9
  editor?: boolean;
10
+ https?: boolean;
11
+ serverOptions?: ServerOptions;
12
+ httpsRedirect?: number;
9
13
  }
10
14
  export declare function importMiqroJSON(inFile: string): MiqroJSON;
11
15
  export declare function getPORT(): string;
@@ -33,6 +37,9 @@ export interface Arguments {
33
37
  services: string[];
34
38
  editor: boolean;
35
39
  hotreload: boolean;
40
+ https: boolean;
41
+ serverOptions: ServerOptions;
42
+ httpsRedirect?: number;
36
43
  }
37
44
  /**
38
45
  * parse process.argv arguments
@@ -21,7 +21,10 @@ const MiqroJSONSchema = {
21
21
  inflateDir: "string?",
22
22
  browser: "boolean?|string?",
23
23
  logFile: "boolean?|string?",
24
- editor: "boolean?"
24
+ editor: "boolean?",
25
+ https: "boolean?",
26
+ serverOptions: "any?",
27
+ httpsRedirect: "number?"
25
28
  }
26
29
  };
27
30
  export function importMiqroJSON(inFile) {
@@ -44,6 +47,9 @@ export function parseArguments() {
44
47
  //env["LOG_FILE"] = env["LOG_FILE"] ? env["LOG_FILE"] : "./server.log";
45
48
  const args = cluster.isPrimary ? process.argv.slice(2, process.argv.length) : process.argv.slice(3, process.argv.length);
46
49
  const flags = {
50
+ httpsRedirect: null,
51
+ https: null,
52
+ serverOptions: {},
47
53
  name: null,
48
54
  browser: null,
49
55
  logFile: null,
@@ -130,6 +136,59 @@ export function parseArguments() {
130
136
  }
131
137
  flags.hotreload = true;
132
138
  continue;
139
+ case "--https":
140
+ if (flags.https !== null) {
141
+ console.error("bad arguments.");
142
+ console.error(usage);
143
+ process.exit(EXIT_CODES.BAD_ARGUMENTS);
144
+ }
145
+ flags.https = true;
146
+ continue;
147
+ case "--https-redirect":
148
+ if (flags.httpsRedirect !== null) {
149
+ console.error("bad arguments.");
150
+ console.error(usage);
151
+ process.exit(EXIT_CODES.BAD_ARGUMENTS);
152
+ }
153
+ const httpsRedirectPort = parseInt(String(args[i + 1]), 10);
154
+ if (isNaN(httpsRedirectPort)) {
155
+ console.error("bad arguments. --https-redirect must be a number.");
156
+ console.error(usage);
157
+ process.exit(EXIT_CODES.BAD_ARGUMENTS);
158
+ }
159
+ flags.httpsRedirect = httpsRedirectPort;
160
+ i++;
161
+ continue;
162
+ case "--https-cert":
163
+ if (flags.serverOptions.cert) {
164
+ console.error("bad arguments.");
165
+ console.error(usage);
166
+ process.exit(EXIT_CODES.BAD_ARGUMENTS);
167
+ }
168
+ const httpsCertPath = args[i + 1];
169
+ if (typeof httpsCertPath !== "string") {
170
+ console.error("bad arguments. --https-cert must be a string.");
171
+ console.error(usage);
172
+ process.exit(EXIT_CODES.BAD_ARGUMENTS);
173
+ }
174
+ flags.serverOptions.cert = readFileSync(httpsCertPath);
175
+ i++;
176
+ continue;
177
+ case "--https-key":
178
+ if (flags.serverOptions.key) {
179
+ console.error("bad arguments.");
180
+ console.error(usage);
181
+ process.exit(EXIT_CODES.BAD_ARGUMENTS);
182
+ }
183
+ const httpsKeyPath = args[i + 1];
184
+ if (typeof httpsKeyPath !== "string") {
185
+ console.error("bad arguments. --https-key must be a string.");
186
+ console.error(usage);
187
+ process.exit(EXIT_CODES.BAD_ARGUMENTS);
188
+ }
189
+ flags.serverOptions.key = readFileSync(httpsKeyPath);
190
+ i++;
191
+ continue;
133
192
  case "--port":
134
193
  if (flags.port !== null) {
135
194
  console.error("bad arguments.");
@@ -356,6 +415,7 @@ export function parseArguments() {
356
415
  flags.inflateDir = flags.inflateDir ? flags.inflateDir : undefined;
357
416
  const miqroJSONPath = !flags.disableMiqroJSON ? flags.miqroJSONPath ? resolve(flags.miqroJSONPath) : getMiqroJSONPath() : false;
358
417
  const miqroRC = miqroJSONPath ? importMiqroJSON(miqroJSONPath) : {};
418
+ //console.dir(miqroRC.serverOptions);
359
419
  // try to load .miqrorc
360
420
  if (!flags.disableMiqroJSON && miqroJSONPath) {
361
421
  if (services.length === 0) {
@@ -365,6 +425,32 @@ export function parseArguments() {
365
425
  }
366
426
  }
367
427
  }
428
+ if (flags.https === null) {
429
+ if (miqroRC.https) {
430
+ flags.https = miqroRC.https;
431
+ }
432
+ }
433
+ if (flags.httpsRedirect === null) {
434
+ if (miqroRC.httpsRedirect && flags.https) {
435
+ /*console.log("reading key from " + String(miqroRC.serverOptions?.key));
436
+ flags.serverOptions.key = readFileSync(String(miqroRC.serverOptions?.key));*/
437
+ flags.httpsRedirect = miqroRC.httpsRedirect;
438
+ }
439
+ }
440
+ if (!flags.serverOptions.key) {
441
+ if (miqroRC.serverOptions?.key) {
442
+ /*console.log("reading key from " + String(miqroRC.serverOptions?.key));
443
+ flags.serverOptions.key = readFileSync(String(miqroRC.serverOptions?.key));*/
444
+ flags.serverOptions.key = miqroRC.serverOptions?.key;
445
+ }
446
+ }
447
+ if (!flags.serverOptions.cert) {
448
+ if (miqroRC.serverOptions?.cert) {
449
+ /*console.log("reading cert from " + String(miqroRC.serverOptions?.cert));
450
+ flags.serverOptions.cert = readFileSync(String(miqroRC.serverOptions?.cert));*/
451
+ flags.serverOptions.cert = miqroRC.serverOptions?.cert;
452
+ }
453
+ }
368
454
  if (flags.port === null) {
369
455
  if (miqroRC.port) {
370
456
  flags.port = String(miqroRC.port);
@@ -460,6 +546,18 @@ export function parseArguments() {
460
546
  process.exit(EXIT_CODES.BAD_ARGUMENTS);
461
547
  }
462
548
  const generateDocType = flags.generateDocType ? flags.generateDocType : "MD";
549
+ if (flags.https && (!flags.serverOptions.key)) {
550
+ console.error("bad arguments. cannot use --https without --https-key. or set values in miqro.json file.");
551
+ process.exit(EXIT_CODES.BAD_ARGUMENTS);
552
+ }
553
+ if (flags.https && (!flags.serverOptions.cert)) {
554
+ console.error("bad arguments. cannot use --https without --https-cert. or set values in miqro.json file.");
555
+ process.exit(EXIT_CODES.BAD_ARGUMENTS);
556
+ }
557
+ if (flags.httpsRedirect && !flags.https) {
558
+ console.error("bad arguments. cannot use --https-redirect without --https. or set values in miqro.json file.");
559
+ process.exit(EXIT_CODES.BAD_ARGUMENTS);
560
+ }
463
561
  return {
464
562
  name: flags.name ? flags.name : undefined,
465
563
  browser: flags.browser !== null ? flags.browser : undefined,
@@ -483,6 +581,9 @@ export function parseArguments() {
483
581
  generateDocOut: flags.generateDocOut ? resolve(process.cwd(), flags.generateDocOut) : generateDocType === "MD" ? resolve(process.cwd(), "API.md") : resolve(process.cwd(), "API.json"),
484
582
  generateDocType,
485
583
  services,
486
- editor: flags.editor ? true : false
584
+ editor: flags.editor ? true : false,
585
+ https: flags.https ? true : false,
586
+ httpsRedirect: flags.httpsRedirect ? flags.httpsRedirect : undefined,
587
+ serverOptions: flags.serverOptions
487
588
  };
488
589
  }
@@ -1,3 +1,3 @@
1
1
  export declare const BIN_NAME = "miqro";
2
2
  export declare const usage = "usage: miqro [...FLAGS] --service app/\n\n==examples==\n\nmiqro --watch --service front/\nPORT=8181 miqro --service api/ --service front/\nmiqro --test --service front/\nmiqro --inflate --service front/\nmiqro --generate-doc --generate-doc-out API.md --service front/\nCLUSTER_COUNT=10 miqro-cluster --service api/";
3
- export declare const help = "\n==flags==\n\n-v, --version\n\toutputs the version number\n-h, --help\n\toutputs this page.\n--watch\n\tuse to enable the hot-reload functionality.\n--test\n\trun the tests for a service.\n--migrate-up\n\tmigrations up.\n--migrate-down\n\tmigrations down.\n--inflate\n\tinflates the application.\n--inflate-dir\n\tto set the output directory of the --inflate command. default value is inflated/.\n--editor\n\truns the application with a built-in editor.\n--generate-doc\n\tgenerates a documentation for the api endpoints of the service.\n--generate-doc-out\n\tthe output file for the generated documentation. default value is API.md.\n--generate-doc-type\n\tthe format of the generated documentation. it can be JSON or MD. default value is MD.\n--generate-doc-all\n\toutputs all the server routes in the documentation output.\n--compile\n\tinflates the application and tries to create a NODE SEA binary.\n--inflate-sea\n\tinflates the application with sea compilation scripts.\n--install-tsconfig\n\tcreates a tsconfig.json configured to use with --install-types.\n--install-types\n\tcreates and updates the .types/ folder use together with --install-tsconfig.\n--install-miqrojson\n\tcreates a default miqro.json file.\n--disable-miqrojson\n\tdisables the load of miqro.json file.\n--log-file\n\toverrides the default log file from LOG_FILE.\n--browser\n\toverrides the default browser from BROWSER.\n--config\n\toverrides the default miqro.json path.\n--port\n\toverrides the default port from PORT.\n--name\n\toverrides the default name of the server.\n\n==environment variables==\n\nPORT\n\toverride the default 8080 port.\nBROWSER\n\toverride the default browser. change to none to disable.\".\nLOG_FILE\n\toverride the default ./server.log file\nDB\n\tenable the server.db features\nDB_STORAGE\n\toverride the default local db location ./db.sqlite3\nDB_DIALECT\n\toverride the default node:sqlite\nDB_CONNECTION\n\toverride the default connection url\nCLEAR_JSX_CACHE\n\tset to 1 or 0 to enable or disable the clearing of the esbuild cache defaults to 1.\nJSX_TMP\n\tset custom location of esbuild builds defaults to /tmp/jsx_tmp.\n";
3
+ export declare const help = "\n==flags==\n\n-v, --version\n\toutputs the version number\n-h, --help\n\toutputs this page.\n--watch\n\tuse to enable the hot-reload functionality.\n--test\n\trun the tests for a service.\n--migrate-up\n\tmigrations up.\n--migrate-down\n\tmigrations down.\n--inflate\n\tinflates the application.\n--inflate-dir\n\tto set the output directory of the --inflate command. default value is inflated/.\n--editor\n\truns the application with a built-in editor.\n--generate-doc\n\tgenerates a documentation for the api endpoints of the service.\n--generate-doc-out\n\tthe output file for the generated documentation. default value is API.md.\n--generate-doc-type\n\tthe format of the generated documentation. it can be JSON or MD. default value is MD.\n--generate-doc-all\n\toutputs all the server routes in the documentation output.\n--compile\n\tinflates the application and tries to create a NODE SEA binary.\n--inflate-sea\n\tinflates the application with sea compilation scripts.\n--install-tsconfig\n\tcreates a tsconfig.json configured to use with --install-types.\n--install-types\n\tcreates and updates the .types/ folder use together with --install-tsconfig.\n--install-miqrojson\n\tcreates a default miqro.json file.\n--disable-miqrojson\n\tdisables the load of miqro.json file.\n--log-file\n\toverrides the default log file from LOG_FILE.\n--browser\n\toverrides the default browser from BROWSER.\n--config\n\toverrides the default miqro.json path.\n--port\n\toverrides the default port from PORT.\n--name\n\toverrides the default name of the server.\n--https\n\tserves the server in https instead of http\n--https-key\n\tpoint to a server.key file for https.\n--https-cert\n\tpoint to a server.cert file for https.\n--https-redirect\n\tserves an aditional http server that redirects to https. it needs a port number.\n\n==environment variables==\n\nPORT\n\toverride the default 8080 port.\nBROWSER\n\toverride the default browser. change to none to disable.\".\nLOG_FILE\n\toverride the default ./server.log file\nDB\n\tenable the server.db features\nDB_STORAGE\n\toverride the default local db location ./db.sqlite3\nDB_DIALECT\n\toverride the default node:sqlite\nDB_CONNECTION\n\toverride the default connection url\nCLEAR_JSX_CACHE\n\tset to 1 or 0 to enable or disable the clearing of the esbuild cache defaults to 1.\nJSX_TMP\n\tset custom location of esbuild builds defaults to /tmp/jsx_tmp.\n";
@@ -37,6 +37,10 @@ export const help = `
37
37
  --config\n\toverrides the default miqro.json path.
38
38
  --port\n\toverrides the default port from PORT.
39
39
  --name\n\toverrides the default name of the server.
40
+ --https\n\tserves the server in https instead of http
41
+ --https-key\n\tpoint to a server.key file for https.
42
+ --https-cert\n\tpoint to a server.cert file for https.
43
+ --https-redirect\n\tserves an aditional http server that redirects to https. it needs a port number.
40
44
 
41
45
  ==environment variables==
42
46
 
@@ -21,7 +21,10 @@ async function main(args) {
21
21
  services: args.services,
22
22
  browser: args.browser,
23
23
  logFile: args.logFile,
24
- hotreload: args.test ? false : args.hotreload
24
+ hotreload: args.test ? false : args.hotreload,
25
+ https: args.test ? false : args.https,
26
+ serverOptions: args.serverOptions,
27
+ httpRedirect: args.test ? undefined : args.httpsRedirect
25
28
  });
26
29
  // check arguments
27
30
  if (args.generateDoc) {
@@ -11,6 +11,7 @@ import { EditorAdminInterface } from "../../editor/common/admin-interface.js";
11
11
  import { LogProvider, LogProviderOptions } from "./utils/log.js";
12
12
  import { MigrationModule } from "../inflate/setup-db.js";
13
13
  import { LogConfigMap } from "../inflate/setup-log.js";
14
+ import { ServerOptions } from "node:https";
14
15
  export interface MiqroOptions {
15
16
  name: string;
16
17
  logger?: Logger;
@@ -21,6 +22,9 @@ export interface MiqroOptions {
21
22
  browser?: string | boolean;
22
23
  logFile?: string | boolean;
23
24
  hotreload?: boolean;
25
+ serverOptions?: ServerOptions<any, any>;
26
+ https?: boolean;
27
+ httpRedirect?: number;
24
28
  }
25
29
  export interface InflateOptions {
26
30
  inflateDir?: string;
@@ -50,6 +54,7 @@ export declare class Miqro {
50
54
  status: "stopped" | "starting" | "stopping" | "reloading" | "started";
51
55
  options: MiqroOptions;
52
56
  server?: App | null;
57
+ httpsRedirectServer?: App | null;
53
58
  cache: ClusterCache;
54
59
  localCache: LocalCache;
55
60
  webSocketManager: WebSocketManager;
@@ -30,6 +30,7 @@ export class Miqro {
30
30
  status = "stopped";
31
31
  options;
32
32
  server = null;
33
+ httpsRedirectServer = null;
33
34
  cache;
34
35
  localCache;
35
36
  webSocketManager;
@@ -343,6 +344,7 @@ export class Miqro {
343
344
  //this.disconnect();
344
345
  this.status = "starting";
345
346
  this.server = undefined;
347
+ this.httpsRedirectServer = undefined;
346
348
  this.connect();
347
349
  await this.dbManager.connectAll();
348
350
  this.server = new App({
@@ -350,8 +352,17 @@ export class Miqro {
350
352
  req.server = this.serverInterface;
351
353
  return this.webSocketManager.onUpgrade(req, socket, head);
352
354
  },
353
- loggerFactory: this.loggerProvider.requestLoggerFactory
355
+ loggerFactory: this.loggerProvider.requestLoggerFactory,
356
+ serverOptions: this.options?.serverOptions,
357
+ https: this.options?.https
354
358
  });
359
+ if (this.options?.httpRedirect) {
360
+ this.httpsRedirectServer = new App();
361
+ this.httpsRedirectServer.use(async (req, res) => {
362
+ const hostname = req.headers.host.split(":").length > 1 ? req.headers.host.split(":")[0] : req.headers.host;
363
+ return await res.redirect('https://' + hostname + ":" + this.options.port + req.url);
364
+ });
365
+ }
355
366
  this.webSocketManager.replaceALLWS(this.inflated.wsConfigList);
356
367
  reloadInflatedRouter(this);
357
368
  await notifiyServerConfig(this.logger, this.serverInterface, this.adminInterface, this.inflated.serverConfigMap, "load");
@@ -368,11 +379,20 @@ export class Miqro {
368
379
  }
369
380
  this.logger?.trace("calling listen on [%s]", this.options.port);
370
381
  await this.server.listen(this.options.port);
382
+ if (this.options?.httpRedirect) {
383
+ await this.httpsRedirectServer.listen(this.options.httpRedirect);
384
+ }
385
+ if (this.options?.httpRedirect && this.logger && (cluster.isPrimary || process.env["CLUSTER_NODE_NUMBER"] === "0")) {
386
+ this.logger?.log("\t\t==listening on [http][%s] for [https][%s] redirection==", this.options?.httpRedirect, this.options.port);
387
+ }
388
+ else if (this.options?.httpRedirect) {
389
+ this.logger?.debug("\t\t==listening on [http][%s] for [https][%s] redirection==", this.options?.httpRedirect, this.options.port);
390
+ }
371
391
  if (this.logger && (cluster.isPrimary || process.env["CLUSTER_NODE_NUMBER"] === "0")) {
372
- this.logger?.log("\t\t==listening on [%s]==", this.options.port);
392
+ this.logger?.log("\t\t==listening on [%s][%s]==", this.options.https ? "https" : "http", this.options.port);
373
393
  }
374
394
  else {
375
- this.logger?.debug("\t\t==listening on [%s]==", this.options.port);
395
+ this.logger?.debug("\t\t==listening on [%s][%s]==", this.options.https ? "https" : "http", this.options.port);
376
396
  }
377
397
  await notifiyServerConfig(this.logger, this.serverInterface, this.adminInterface, this.inflated.serverConfigMap, "start");
378
398
  if (this.options.hotreload && (cluster.isPrimary || process.env["CLUSTER_NODE_NUMBER"] === "0")) {
@@ -392,7 +412,9 @@ export class Miqro {
392
412
  this.watcher = null;
393
413
  }
394
414
  const server = this.server;
415
+ const httpsRedirectServer = this.httpsRedirectServer;
395
416
  this.server = null;
417
+ this.httpsRedirectServer = null;
396
418
  this.disconnect();
397
419
  this.logger?.debug("\t\t==stop==");
398
420
  this.logger?.debug("clear running server routes");
@@ -403,6 +425,9 @@ export class Miqro {
403
425
  notifiyServerConfigSync(this, "unload");
404
426
  //server.ws.disconnectAll();
405
427
  this.logger?.debug("stopping");
428
+ if (httpsRedirectServer) {
429
+ await httpsRedirectServer.close();
430
+ }
406
431
  const p = server.close();
407
432
  await p;
408
433
  await pD;
@@ -6,6 +6,15 @@ export function createServerInterface(options) {
6
6
  cache: options.cache,
7
7
  localCache: options.localCache,
8
8
  logger: options.logger,
9
+ reload() {
10
+ return options?.app?.reload();
11
+ },
12
+ restart() {
13
+ return options?.app?.restart();
14
+ },
15
+ stop() {
16
+ return options?.app?.stop();
17
+ },
9
18
  db: {
10
19
  get(name) {
11
20
  return options.dbManager.getDB(name);
@@ -165,6 +165,15 @@ export interface ServerInterface extends ServerGlobal {
165
165
  transports?: any[];
166
166
  formatter?: any;
167
167
  }) => Logger;
168
+ stop: () => Promise<void>;
169
+ reload: () => Promise<null | {
170
+ filePath: string;
171
+ error: Error;
172
+ }[]>;
173
+ restart: () => Promise<null | {
174
+ filePath: string;
175
+ error: Error;
176
+ }[]>;
168
177
  }
169
178
  export interface ServerRequest extends Request {
170
179
  server?: ServerInterface;
package/build/lib.cjs CHANGED
@@ -6424,6 +6424,7 @@ var getEnvVariable = (envName, defaults) => {
6424
6424
 
6425
6425
  // node_modules/@miqro/core/build/app.js
6426
6426
  var import_http2 = require("http");
6427
+ var import_https = require("https");
6427
6428
 
6428
6429
  // node_modules/@miqro/core/build/middleware/router.js
6429
6430
  var Router = class {
@@ -6748,7 +6749,8 @@ var App = class extends Router {
6748
6749
  console.error(loggerError);
6749
6750
  }
6750
6751
  };
6751
- this.httpServer = (0, import_http2.createServer)(this.serverOptions, this.listener);
6752
+ const createS = config && config.https ? import_https.createServer : import_http2.createServer;
6753
+ this.httpServer = createS(this.serverOptions, this.listener);
6752
6754
  this.httpServer.on("connection", (conn) => {
6753
6755
  const key = (0, import_crypto2.randomUUID)();
6754
6756
  this.connections[key] = conn;
@@ -16565,6 +16567,15 @@ function createServerInterface(options) {
16565
16567
  cache: options.cache,
16566
16568
  localCache: options.localCache,
16567
16569
  logger: options.logger,
16570
+ reload() {
16571
+ return options?.app?.reload();
16572
+ },
16573
+ restart() {
16574
+ return options?.app?.restart();
16575
+ },
16576
+ stop() {
16577
+ return options?.app?.stop();
16578
+ },
16568
16579
  db: {
16569
16580
  get(name) {
16570
16581
  return options.dbManager.getDB(name);
@@ -16646,7 +16657,10 @@ var MiqroJSONSchema = {
16646
16657
  inflateDir: "string?",
16647
16658
  browser: "boolean?|string?",
16648
16659
  logFile: "boolean?|string?",
16649
- editor: "boolean?"
16660
+ editor: "boolean?",
16661
+ https: "boolean?",
16662
+ serverOptions: "any?",
16663
+ httpsRedirect: "number?"
16650
16664
  }
16651
16665
  };
16652
16666
  function importMiqroJSON(inFile) {
@@ -16774,6 +16788,7 @@ var Miqro = class _Miqro {
16774
16788
  status = "stopped";
16775
16789
  options;
16776
16790
  server = null;
16791
+ httpsRedirectServer = null;
16777
16792
  cache;
16778
16793
  localCache;
16779
16794
  webSocketManager;
@@ -17055,6 +17070,7 @@ var Miqro = class _Miqro {
17055
17070
  this.logger?.debug(" ==start==");
17056
17071
  this.status = "starting";
17057
17072
  this.server = void 0;
17073
+ this.httpsRedirectServer = void 0;
17058
17074
  this.connect();
17059
17075
  await this.dbManager.connectAll();
17060
17076
  this.server = new App({
@@ -17062,8 +17078,17 @@ var Miqro = class _Miqro {
17062
17078
  req.server = this.serverInterface;
17063
17079
  return this.webSocketManager.onUpgrade(req, socket, head);
17064
17080
  },
17065
- loggerFactory: this.loggerProvider.requestLoggerFactory
17081
+ loggerFactory: this.loggerProvider.requestLoggerFactory,
17082
+ serverOptions: this.options?.serverOptions,
17083
+ https: this.options?.https
17066
17084
  });
17085
+ if (this.options?.httpRedirect) {
17086
+ this.httpsRedirectServer = new App();
17087
+ this.httpsRedirectServer.use(async (req, res) => {
17088
+ const hostname = req.headers.host.split(":").length > 1 ? req.headers.host.split(":")[0] : req.headers.host;
17089
+ return await res.redirect("https://" + hostname + ":" + this.options.port + req.url);
17090
+ });
17091
+ }
17067
17092
  this.webSocketManager.replaceALLWS(this.inflated.wsConfigList);
17068
17093
  reloadInflatedRouter(this);
17069
17094
  await notifiyServerConfig(this.logger, this.serverInterface, this.adminInterface, this.inflated.serverConfigMap, "load");
@@ -17080,10 +17105,18 @@ var Miqro = class _Miqro {
17080
17105
  }
17081
17106
  this.logger?.trace("calling listen on [%s]", this.options.port);
17082
17107
  await this.server.listen(this.options.port);
17108
+ if (this.options?.httpRedirect) {
17109
+ await this.httpsRedirectServer.listen(this.options.httpRedirect);
17110
+ }
17111
+ if (this.options?.httpRedirect && this.logger && (import_node_cluster3.default.isPrimary || process.env["CLUSTER_NODE_NUMBER"] === "0")) {
17112
+ this.logger?.log(" ==listening on [http][%s] for [https][%s] redirection==", this.options?.httpRedirect, this.options.port);
17113
+ } else if (this.options?.httpRedirect) {
17114
+ this.logger?.debug(" ==listening on [http][%s] for [https][%s] redirection==", this.options?.httpRedirect, this.options.port);
17115
+ }
17083
17116
  if (this.logger && (import_node_cluster3.default.isPrimary || process.env["CLUSTER_NODE_NUMBER"] === "0")) {
17084
- this.logger?.log(" ==listening on [%s]==", this.options.port);
17117
+ this.logger?.log(" ==listening on [%s][%s]==", this.options.https ? "https" : "http", this.options.port);
17085
17118
  } else {
17086
- this.logger?.debug(" ==listening on [%s]==", this.options.port);
17119
+ this.logger?.debug(" ==listening on [%s][%s]==", this.options.https ? "https" : "http", this.options.port);
17087
17120
  }
17088
17121
  await notifiyServerConfig(this.logger, this.serverInterface, this.adminInterface, this.inflated.serverConfigMap, "start");
17089
17122
  if (this.options.hotreload && (import_node_cluster3.default.isPrimary || process.env["CLUSTER_NODE_NUMBER"] === "0")) {
@@ -17103,7 +17136,9 @@ var Miqro = class _Miqro {
17103
17136
  this.watcher = null;
17104
17137
  }
17105
17138
  const server2 = this.server;
17139
+ const httpsRedirectServer = this.httpsRedirectServer;
17106
17140
  this.server = null;
17141
+ this.httpsRedirectServer = null;
17107
17142
  this.disconnect();
17108
17143
  this.logger?.debug(" ==stop==");
17109
17144
  this.logger?.debug("clear running server routes");
@@ -17113,6 +17148,9 @@ var Miqro = class _Miqro {
17113
17148
  const pD = this.dbManager.deleteAll();
17114
17149
  notifiyServerConfigSync(this, "unload");
17115
17150
  this.logger?.debug("stopping");
17151
+ if (httpsRedirectServer) {
17152
+ await httpsRedirectServer.close();
17153
+ }
17116
17154
  const p = server2.close();
17117
17155
  await p;
17118
17156
  await pD;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "miqro",
3
- "version": "6.2.0",
3
+ "version": "6.2.1",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "build/esm/src/lib.js",
@@ -43,7 +43,7 @@
43
43
  "typescript": "^5.7.2"
44
44
  },
45
45
  "dependencies": {
46
- "@miqro/core": "^5.0.14",
46
+ "@miqro/core": "^5.0.15",
47
47
  "@miqro/jsx": "^1.0.0",
48
48
  "@miqro/jsx-dom": "^1.0.3",
49
49
  "@miqro/jsx-node": "^1.0.5",