miqro 6.2.0 → 6.2.2

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
 
@@ -16,6 +16,7 @@ export interface InflateOptions {
16
16
  embemedJSX: boolean;
17
17
  minify: boolean;
18
18
  useExport: boolean;
19
+ platform?: string;
19
20
  logger?: Logger | Console;
20
21
  }
21
22
  export declare function inflateJSX(inFile: string, options: InflateOptions): Promise<string>;
@@ -49,7 +49,8 @@ export async function inflateJSX(inFile, options) {
49
49
  const { outputFiles: [{ contents }] } = await esBuild({
50
50
  ...DEFAULT_ESOPTION,
51
51
  entryPoints: [inFileTmp],
52
- minify: options.minify
52
+ minify: options.minify,
53
+ platform: options.platform ? options.platform : DEFAULT_ESOPTION.platform
53
54
  });
54
55
  if (CLEAR_JSX_CACHE) {
55
56
  logger?.trace("clearing cache at [%s] to change this behaivor set CLEAR_JSX_CACHE to 0", tmpBuildDir);
@@ -69,7 +70,8 @@ export async function inflateJSX(inFile, options) {
69
70
  const { outputFiles: [{ contents }] } = await esBuild({
70
71
  ...DEFAULT_ESOPTION,
71
72
  entryPoints: [inFileTmp],
72
- minify: options.minify
73
+ minify: options.minify,
74
+ platform: options.platform ? options.platform : DEFAULT_ESOPTION.platform
73
75
  });
74
76
  if (CLEAR_JSX_CACHE) {
75
77
  logger?.trace("clearing cache at [%s] to change this behaivor set CLEAR_JSX_CACHE to 0", tmpBuildDir);
@@ -397,10 +399,12 @@ export async function importJSXFile(inFile, logger) {
397
399
  embemedJSX: false,
398
400
  minify: false,
399
401
  useExport: true,
402
+ platform: "node",
400
403
  logger
401
404
  });
402
405
  const tmpBuildDir = resolve(JSX_TMP_DIR, String(process.pid), "import", Date.now() + "-" + randomUUID());
403
- const inFileTmp = resolve(tmpBuildDir, basename(inFile) + ".mjs");
406
+ //const inFileTmp = resolve(tmpBuildDir, basename(inFile) + ".mjs");
407
+ const inFileTmp = resolve(tmpBuildDir, basename(inFile) + ".cjs");
404
408
  //const logger = getLogger(`${SERVER_IDENTIFIER}_JSX`);
405
409
  mkdirSync(tmpBuildDir, {
406
410
  recursive: true
@@ -410,18 +414,18 @@ export async function importJSXFile(inFile, logger) {
410
414
  assertGlobalTampered();
411
415
  logger?.trace("importing [%s] from [%s]. to change the import folder set JSX_TMP", relative(cwd(), inFile), dirname(relative(JSX_TMP_DIR, inFileTmp)));
412
416
  logger?.debug("importing [%s]", relative(cwd(), inFile));
413
- const module = await import(inFileTmp);
417
+ const module = await import(resolve(inFileTmp));
414
418
  assertGlobalTampered();
415
419
  if (CLEAR_JSX_CACHE) {
416
420
  logger?.trace("clearing cache at [%s]. to change this behaivor set CLEAR_JSX_CACHE to 0", tmpBuildDir);
417
421
  unlinkSync(inFileTmp);
418
422
  rmdirSync(tmpBuildDir);
419
423
  }
420
- return module;
424
+ return module.default;
421
425
  }
422
426
  catch (e) {
423
427
  logger?.error(e);
424
- logger?.error("error with: " + inFile);
428
+ logger?.error("error with2: " + inFile);
425
429
  if (CLEAR_JSX_CACHE) {
426
430
  logger?.trace("clearing cache at [%s] to change this behaivor set CLEAR_JSX_CACHE to 0", tmpBuildDir);
427
431
  unlinkSync(inFileTmp);
@@ -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;
@@ -17,7 +17,10 @@ function tryConnection() {
17
17
  const newSocket = getSocket();
18
18
  newSocket.addEventListener("open", (event) => {
19
19
  console.log("reloading");
20
- window.location.reload();
20
+ setTimeout(()=>{
21
+ window.location.reload();
22
+ }, 500);
23
+
21
24
  });
22
25
  newSocket.addEventListener("error", (err) => {
23
26
  console.error(err);
@@ -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);
@@ -10,7 +10,7 @@ export class WebSocketManager {
10
10
  this.onUpgrade = this.onUpgrade.bind(this);
11
11
  this.logger = options && options.logger ? options.logger : null;
12
12
  this.name = options && options.name ? options.name : "WebSocketManager";
13
- this.loggerProvider = options.loggerProvider;
13
+ this.loggerProvider = options && options.loggerProvider;
14
14
  this.avoidLogSocket = options && options.avoidLogSocket ? options.avoidLogSocket : false;
15
15
  }
16
16
  deleteWS(path) {
@@ -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;
@@ -9058,7 +9060,7 @@ var WebSocketManager = class {
9058
9060
  this.onUpgrade = this.onUpgrade.bind(this);
9059
9061
  this.logger = options && options.logger ? options.logger : null;
9060
9062
  this.name = options && options.name ? options.name : "WebSocketManager";
9061
- this.loggerProvider = options.loggerProvider;
9063
+ this.loggerProvider = options && options.loggerProvider;
9062
9064
  this.avoidLogSocket = options && options.avoidLogSocket ? options.avoidLogSocket : false;
9063
9065
  }
9064
9066
  deleteWS(path) {
@@ -14341,7 +14343,8 @@ async function inflateJSX(inFile, options) {
14341
14343
  const { outputFiles: [{ contents }] } = await esBuild({
14342
14344
  ...DEFAULT_ESOPTION,
14343
14345
  entryPoints: [inFileTmp],
14344
- minify: options.minify
14346
+ minify: options.minify,
14347
+ platform: options.platform ? options.platform : DEFAULT_ESOPTION.platform
14345
14348
  });
14346
14349
  if (CLEAR_JSX_CACHE) {
14347
14350
  logger?.trace("clearing cache at [%s] to change this behaivor set CLEAR_JSX_CACHE to 0", tmpBuildDir);
@@ -14358,7 +14361,8 @@ async function inflateJSX(inFile, options) {
14358
14361
  const { outputFiles: [{ contents }] } = await esBuild({
14359
14362
  ...DEFAULT_ESOPTION,
14360
14363
  entryPoints: [inFileTmp],
14361
- minify: options.minify
14364
+ minify: options.minify,
14365
+ platform: options.platform ? options.platform : DEFAULT_ESOPTION.platform
14362
14366
  });
14363
14367
  if (CLEAR_JSX_CACHE) {
14364
14368
  logger?.trace("clearing cache at [%s] to change this behaivor set CLEAR_JSX_CACHE to 0", tmpBuildDir);
@@ -14659,10 +14663,11 @@ async function importJSXFile(inFile, logger) {
14659
14663
  embemedJSX: false,
14660
14664
  minify: false,
14661
14665
  useExport: true,
14666
+ platform: "node",
14662
14667
  logger
14663
14668
  });
14664
14669
  const tmpBuildDir = (0, import_node_path5.resolve)(JSX_TMP_DIR, String(process.pid), "import", Date.now() + "-" + (0, import_node_crypto4.randomUUID)());
14665
- const inFileTmp = (0, import_node_path5.resolve)(tmpBuildDir, (0, import_node_path5.basename)(inFile) + ".mjs");
14670
+ const inFileTmp = (0, import_node_path5.resolve)(tmpBuildDir, (0, import_node_path5.basename)(inFile) + ".cjs");
14666
14671
  (0, import_node_fs6.mkdirSync)(tmpBuildDir, {
14667
14672
  recursive: true
14668
14673
  });
@@ -14671,17 +14676,17 @@ async function importJSXFile(inFile, logger) {
14671
14676
  assertGlobalTampered();
14672
14677
  logger?.trace("importing [%s] from [%s]. to change the import folder set JSX_TMP", (0, import_node_path5.relative)((0, import_node_process3.cwd)(), inFile), (0, import_node_path5.dirname)((0, import_node_path5.relative)(JSX_TMP_DIR, inFileTmp)));
14673
14678
  logger?.debug("importing [%s]", (0, import_node_path5.relative)((0, import_node_process3.cwd)(), inFile));
14674
- const module2 = await import(inFileTmp);
14679
+ const module2 = await import((0, import_node_path5.resolve)(inFileTmp));
14675
14680
  assertGlobalTampered();
14676
14681
  if (CLEAR_JSX_CACHE) {
14677
14682
  logger?.trace("clearing cache at [%s]. to change this behaivor set CLEAR_JSX_CACHE to 0", tmpBuildDir);
14678
14683
  (0, import_node_fs6.unlinkSync)(inFileTmp);
14679
14684
  (0, import_node_fs6.rmdirSync)(tmpBuildDir);
14680
14685
  }
14681
- return module2;
14686
+ return module2.default;
14682
14687
  } catch (e) {
14683
14688
  logger?.error(e);
14684
- logger?.error("error with: " + inFile);
14689
+ logger?.error("error with2: " + inFile);
14685
14690
  if (CLEAR_JSX_CACHE) {
14686
14691
  logger?.trace("clearing cache at [%s] to change this behaivor set CLEAR_JSX_CACHE to 0", tmpBuildDir);
14687
14692
  (0, import_node_fs6.unlinkSync)(inFileTmp);
@@ -14733,7 +14738,10 @@ function tryConnection() {
14733
14738
  const newSocket = getSocket();
14734
14739
  newSocket.addEventListener("open", (event) => {
14735
14740
  console.log("reloading");
14736
- window.location.reload();
14741
+ setTimeout(()=>{
14742
+ window.location.reload();
14743
+ }, 500);
14744
+
14737
14745
  });
14738
14746
  newSocket.addEventListener("error", (err) => {
14739
14747
  console.error(err);
@@ -16565,6 +16573,15 @@ function createServerInterface(options) {
16565
16573
  cache: options.cache,
16566
16574
  localCache: options.localCache,
16567
16575
  logger: options.logger,
16576
+ reload() {
16577
+ return options?.app?.reload();
16578
+ },
16579
+ restart() {
16580
+ return options?.app?.restart();
16581
+ },
16582
+ stop() {
16583
+ return options?.app?.stop();
16584
+ },
16568
16585
  db: {
16569
16586
  get(name) {
16570
16587
  return options.dbManager.getDB(name);
@@ -16646,7 +16663,10 @@ var MiqroJSONSchema = {
16646
16663
  inflateDir: "string?",
16647
16664
  browser: "boolean?|string?",
16648
16665
  logFile: "boolean?|string?",
16649
- editor: "boolean?"
16666
+ editor: "boolean?",
16667
+ https: "boolean?",
16668
+ serverOptions: "any?",
16669
+ httpsRedirect: "number?"
16650
16670
  }
16651
16671
  };
16652
16672
  function importMiqroJSON(inFile) {
@@ -16774,6 +16794,7 @@ var Miqro = class _Miqro {
16774
16794
  status = "stopped";
16775
16795
  options;
16776
16796
  server = null;
16797
+ httpsRedirectServer = null;
16777
16798
  cache;
16778
16799
  localCache;
16779
16800
  webSocketManager;
@@ -17055,6 +17076,7 @@ var Miqro = class _Miqro {
17055
17076
  this.logger?.debug(" ==start==");
17056
17077
  this.status = "starting";
17057
17078
  this.server = void 0;
17079
+ this.httpsRedirectServer = void 0;
17058
17080
  this.connect();
17059
17081
  await this.dbManager.connectAll();
17060
17082
  this.server = new App({
@@ -17062,8 +17084,17 @@ var Miqro = class _Miqro {
17062
17084
  req.server = this.serverInterface;
17063
17085
  return this.webSocketManager.onUpgrade(req, socket, head);
17064
17086
  },
17065
- loggerFactory: this.loggerProvider.requestLoggerFactory
17087
+ loggerFactory: this.loggerProvider.requestLoggerFactory,
17088
+ serverOptions: this.options?.serverOptions,
17089
+ https: this.options?.https
17066
17090
  });
17091
+ if (this.options?.httpRedirect) {
17092
+ this.httpsRedirectServer = new App();
17093
+ this.httpsRedirectServer.use(async (req, res) => {
17094
+ const hostname = req.headers.host.split(":").length > 1 ? req.headers.host.split(":")[0] : req.headers.host;
17095
+ return await res.redirect("https://" + hostname + ":" + this.options.port + req.url);
17096
+ });
17097
+ }
17067
17098
  this.webSocketManager.replaceALLWS(this.inflated.wsConfigList);
17068
17099
  reloadInflatedRouter(this);
17069
17100
  await notifiyServerConfig(this.logger, this.serverInterface, this.adminInterface, this.inflated.serverConfigMap, "load");
@@ -17080,10 +17111,18 @@ var Miqro = class _Miqro {
17080
17111
  }
17081
17112
  this.logger?.trace("calling listen on [%s]", this.options.port);
17082
17113
  await this.server.listen(this.options.port);
17114
+ if (this.options?.httpRedirect) {
17115
+ await this.httpsRedirectServer.listen(this.options.httpRedirect);
17116
+ }
17117
+ if (this.options?.httpRedirect && this.logger && (import_node_cluster3.default.isPrimary || process.env["CLUSTER_NODE_NUMBER"] === "0")) {
17118
+ this.logger?.log(" ==listening on [http][%s] for [https][%s] redirection==", this.options?.httpRedirect, this.options.port);
17119
+ } else if (this.options?.httpRedirect) {
17120
+ this.logger?.debug(" ==listening on [http][%s] for [https][%s] redirection==", this.options?.httpRedirect, this.options.port);
17121
+ }
17083
17122
  if (this.logger && (import_node_cluster3.default.isPrimary || process.env["CLUSTER_NODE_NUMBER"] === "0")) {
17084
- this.logger?.log(" ==listening on [%s]==", this.options.port);
17123
+ this.logger?.log(" ==listening on [%s][%s]==", this.options.https ? "https" : "http", this.options.port);
17085
17124
  } else {
17086
- this.logger?.debug(" ==listening on [%s]==", this.options.port);
17125
+ this.logger?.debug(" ==listening on [%s][%s]==", this.options.https ? "https" : "http", this.options.port);
17087
17126
  }
17088
17127
  await notifiyServerConfig(this.logger, this.serverInterface, this.adminInterface, this.inflated.serverConfigMap, "start");
17089
17128
  if (this.options.hotreload && (import_node_cluster3.default.isPrimary || process.env["CLUSTER_NODE_NUMBER"] === "0")) {
@@ -17103,7 +17142,9 @@ var Miqro = class _Miqro {
17103
17142
  this.watcher = null;
17104
17143
  }
17105
17144
  const server2 = this.server;
17145
+ const httpsRedirectServer = this.httpsRedirectServer;
17106
17146
  this.server = null;
17147
+ this.httpsRedirectServer = null;
17107
17148
  this.disconnect();
17108
17149
  this.logger?.debug(" ==stop==");
17109
17150
  this.logger?.debug("clear running server routes");
@@ -17113,6 +17154,9 @@ var Miqro = class _Miqro {
17113
17154
  const pD = this.dbManager.deleteAll();
17114
17155
  notifiyServerConfigSync(this, "unload");
17115
17156
  this.logger?.debug("stopping");
17157
+ if (httpsRedirectServer) {
17158
+ await httpsRedirectServer.close();
17159
+ }
17116
17160
  const p = server2.close();
17117
17161
  await p;
17118
17162
  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.2",
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",