@vandenberghinc/volt 1.1.7 → 1.1.9

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.
@@ -29,7 +29,7 @@ import { Endpoint, EndpointOptions } from "./endpoint.js";
29
29
  import { ImageEndpoint } from "./image_endpoint.js";
30
30
  import { Stream } from "./stream.js";
31
31
  import { Database, Collection, UIDCollection } from "./database.js";
32
- import { /*StaticFileWatcher,*/ FileWatcher } from "./file_watcher.js";
32
+ // import { /*StaticFileWatcher,*/ FileWatcher } from "./file_watcher.js";
33
33
  import { Users } from "./users.js";
34
34
  import { Paddle } from "./payments/paddle.js";
35
35
  import { RateLimits, RateLimitServer, RateLimitClient } from "./rate_limit.js";
@@ -769,6 +769,7 @@ export class Server {
769
769
  // Instance properties
770
770
  public ip: string;
771
771
  public port: number;
772
+ public https_port: number;
772
773
  public domain: string;
773
774
  public full_domain: string;
774
775
  public source: vlib.Path; // vlib.Path type
@@ -781,7 +782,7 @@ export class Server {
781
782
  public token_expiration: number;
782
783
  public google_tag?: string;
783
784
  public production: boolean;
784
- public localhost: boolean;
785
+ // public localhost: boolean;
785
786
  public multiprocessing: boolean;
786
787
  public processes: number;
787
788
  public company: CompanyInfo;
@@ -794,7 +795,7 @@ export class Server {
794
795
  public additional_sitemap_endpoints: string[];
795
796
  public log_level: number;
796
797
  public tls?: TLSConfig;
797
- public file_watcher?: FileWatcher;
798
+ // public file_watcher?: FileWatcher;
798
799
  // public admin: AdminConfig;
799
800
  // public ts: TypeScriptConfig;
800
801
  public lightweight: boolean;
@@ -820,7 +821,7 @@ export class Server {
820
821
  private _on_stop: Array<() => void | Promise<void>>;
821
822
  // public browser_preview?: BrowserPreview;
822
823
  // public static_file_watcher: StaticFileWatcher;
823
- public is_file_watcher: boolean;
824
+ // public is_file_watcher: boolean;
824
825
  public daemon?: vlib.Daemon;
825
826
  private _stop_tscompiler_watcher?: () => void;
826
827
 
@@ -832,8 +833,8 @@ export class Server {
832
833
  public logger: typeof logger;
833
834
 
834
835
  constructor({
835
- ip = "127.0.0.1",
836
- port = 8000,
836
+ ip, // leave undefined for blank detection.
837
+ port, // leave undefined for blank detection.
837
838
  domain,
838
839
  is_primary = true,
839
840
  source,
@@ -878,10 +879,10 @@ export class Server {
878
879
  enable_account_activation = true,
879
880
  // honey_pot_key = null,
880
881
  production = false,
881
- localhost = true,
882
+ // localhost = true,
882
883
  multiprocessing = true,
883
884
  processes = null,
884
- file_watcher = false,
885
+ // file_watcher = false,
885
886
  offline = false,
886
887
  additional_sitemap_endpoints = [],
887
888
  log_level = 0,
@@ -920,10 +921,10 @@ export class Server {
920
921
  enable_account_activation?: boolean;
921
922
  // honey_pot_key?: string | null;
922
923
  production?: boolean;
923
- localhost?: boolean;
924
+ // localhost?: boolean;
924
925
  multiprocessing?: boolean;
925
926
  processes?: number | null;
926
- file_watcher?: FileWatcher | Record<string, any> | boolean;
927
+ // file_watcher?: FileWatcher | Record<string, any> | boolean;
927
928
  offline?: boolean;
928
929
  additional_sitemap_endpoints?: string[];
929
930
  log_level?: number;
@@ -1057,10 +1058,10 @@ export class Server {
1057
1058
  enable_2fa: {type: "boolean", required: false},
1058
1059
  enable_account_activation: {type: "boolean", required: false},
1059
1060
  production: {type: "boolean", required: false},
1060
- localhost: { type: "boolean", required: false },
1061
+ // localhost: { type: "boolean", required: false },
1061
1062
  multiprocessing: {type: "boolean", required: false, default: true},
1062
1063
  processes: {type: "number", required: false, default: null},
1063
- file_watcher: {type: ["null", "boolean", "object", FileWatcher], required: false},
1064
+ // file_watcher: {type: ["null", "boolean", "object", FileWatcher], required: false},
1064
1065
  offline: {type: "boolean", default: false},
1065
1066
  additional_sitemap_endpoints: {type: "array", default: []},
1066
1067
  log_level: {type: "number", default: 0},
@@ -1085,8 +1086,14 @@ export class Server {
1085
1086
  }});
1086
1087
 
1087
1088
  // Assign attributes directly.
1088
- this.port = port;
1089
- this.ip = ip;
1089
+ if (production || port == null) {
1090
+ this.port = 80;
1091
+ this.https_port = 443;
1092
+ } else {
1093
+ this.port = port;
1094
+ this.https_port = port + 1;
1095
+ }
1096
+ this.ip = ip ?? "127.0.0.1";
1090
1097
  this.is_primary = is_primary && libcluster.isPrimary;
1091
1098
  this.source = new vlib.Path(source);
1092
1099
  this.favicon = favicon;
@@ -1095,7 +1102,7 @@ export class Server {
1095
1102
  this.token_expiration = token_expiration;
1096
1103
  this.google_tag = google_tag;
1097
1104
  this.production = production;
1098
- this.localhost = localhost;
1105
+ // this.localhost = localhost;
1099
1106
  this.lightweight = lightweight;
1100
1107
  this.multiprocessing = multiprocessing;
1101
1108
  this.processes = processes == null ? os.cpus().length : processes;
@@ -1115,10 +1122,13 @@ export class Server {
1115
1122
  this.err_endpoints = new Map();
1116
1123
 
1117
1124
  // Assign based on localhost.
1118
- if (localhost) {
1119
- this.ip = "127.0.0.1";
1120
- this.domain = this.ip + ":" + (port + (this.tls ? 1 : 0));
1121
- }
1125
+ // if (localhost) {
1126
+ // this.ip = "127.0.0.1";
1127
+ // this.domain = this.ip + ":" + (port + (this.tls ? 1 : 0));
1128
+ // } else if (!production && !localhost && ip == null) { // use argument ip not attr since that already has a default.
1129
+ // this.ip = vlib.Network.private_ip();
1130
+ // this.domain = this.ip + ":" + (port + (this.tls ? 1 : 0));
1131
+ // }
1122
1132
 
1123
1133
  /* @performance */ this.performance = new vlib.Performance("Server performance");
1124
1134
 
@@ -1239,47 +1249,47 @@ export class Server {
1239
1249
  // this.static_file_watcher = new StaticFileWatcher(this);
1240
1250
 
1241
1251
  // Initialize file watcher.
1242
- if (file_watcher !== false) {
1243
- console.warn("[Volt] Argument file_watcher is deprecated. This may be removed in future versions.");
1244
- if (file_watcher == null) {
1245
- // Null.
1246
- file_watcher = {};
1247
- }
1248
- if (!(file_watcher as Record<string, any>).source) {
1249
- // Source.
1250
- (file_watcher as Record<string, any>).source = this.source.str();
1251
- }
1252
- if (!(file_watcher instanceof FileWatcher)) {
1253
- // Initialize.
1254
- file_watcher = new FileWatcher(file_watcher as any);
1255
- }
1256
- this.file_watcher = file_watcher as FileWatcher;
1257
- }
1258
- else {
1259
- this.file_watcher = undefined;
1260
- }
1252
+ // if (file_watcher !== false) {
1253
+ // console.warn("[Volt] Argument file_watcher is deprecated. This may be removed in future versions.");
1254
+ // if (file_watcher == null) {
1255
+ // // Null.
1256
+ // file_watcher = {};
1257
+ // }
1258
+ // if (!(file_watcher as Record<string, any>).source) {
1259
+ // // Source.
1260
+ // (file_watcher as Record<string, any>).source = this.source.str();
1261
+ // }
1262
+ // if (!(file_watcher instanceof FileWatcher)) {
1263
+ // // Initialize.
1264
+ // file_watcher = new FileWatcher(file_watcher as any);
1265
+ // }
1266
+ // this.file_watcher = file_watcher as FileWatcher;
1267
+ // }
1268
+ // else {
1269
+ // this.file_watcher = undefined;
1270
+ // }
1261
1271
 
1262
1272
  // File watcher.
1263
- if (
1264
- process.env.VOLT_NO_FILE_WATCHER == null &&
1265
- !process.argv.includes("--no-file-watcher") &&
1266
- this.production === false &&
1267
- file_watcher !== false &&
1268
- process.env.VOLT_FILE_WATCHER !== '1'
1269
- ) {
1270
-
1271
- // Disable primary for when users access is_primary.
1272
- this.is_primary = false;
1273
-
1274
- // Enable file watcher.
1275
- this.is_file_watcher = true;
1276
- }
1273
+ // if (
1274
+ // process.env.VOLT_NO_FILE_WATCHER == null &&
1275
+ // !process.argv.includes("--no-file-watcher") &&
1276
+ // this.production === false &&
1277
+ // // file_watcher !== false &&
1278
+ // process.env.VOLT_FILE_WATCHER !== '1'
1279
+ // ) {
1280
+
1281
+ // // Disable primary for when users access is_primary.
1282
+ // this.is_primary = false;
1283
+
1284
+ // // Enable file watcher.
1285
+ // this.is_file_watcher = true;
1286
+ // }
1277
1287
 
1278
- // No file watcher.
1279
- else {
1288
+ // // No file watcher.
1289
+ // else {
1280
1290
 
1281
1291
  // Disable file watcher.
1282
- this.is_file_watcher = false;
1292
+ // this.is_file_watcher = false;
1283
1293
 
1284
1294
  // Set logger.
1285
1295
  logger.log_level = this.log_level;
@@ -1341,7 +1351,7 @@ export class Server {
1341
1351
  // this.blacklist = new Blacklist({api_key: this.honey_pot_key});
1342
1352
  // }
1343
1353
 
1344
- }
1354
+ // }
1345
1355
 
1346
1356
  // Other keys.
1347
1357
  this.keys = {};
@@ -1448,9 +1458,9 @@ export class Server {
1448
1458
  }
1449
1459
 
1450
1460
  // Create default endpoints.
1451
- private _create_default_endpoints(): string[] {
1461
+ private _create_default_endpoints() {
1452
1462
  // Vars.
1453
- const additional_file_watcher_paths: string[] = [];
1463
+ // const additional_file_watcher_paths: string[] = [];
1454
1464
 
1455
1465
  // Add favicon.
1456
1466
  if (this.favicon != null) {
@@ -1502,10 +1512,10 @@ export class Server {
1502
1512
  const status: Record<string, any> = {};
1503
1513
  status.ip = this.ip;
1504
1514
  if (this.http) {
1505
- status.http_port = this.port == null ? 80 : (this.port);
1515
+ status.http_port = this.port;
1506
1516
  }
1507
1517
  if (this.https) {
1508
- status.https_port = this.port == null ? 443 : (this.port + 1);
1518
+ status.https_port = this.https_port;
1509
1519
  }
1510
1520
 
1511
1521
  // Load data.
@@ -1564,7 +1574,7 @@ export class Server {
1564
1574
  })
1565
1575
 
1566
1576
  // Handler.
1567
- return additional_file_watcher_paths;
1577
+ // return additional_file_watcher_paths;
1568
1578
  }
1569
1579
 
1570
1580
  // Create the sitemap endpoint.
@@ -1967,55 +1977,51 @@ export class Server {
1967
1977
  /* @performance */ this.performance.start()
1968
1978
 
1969
1979
  // File watcher.
1970
- if (this.is_file_watcher) {
1971
- // Disable primary for when users access is_primary.
1972
- this.is_primary = false;
1980
+ // if (this.is_file_watcher) {
1981
+ // // Disable primary for when users access is_primary.
1982
+ // this.is_primary = false;
1973
1983
 
1974
- // Create default endpoints for excluded static file watch paths.
1975
- this._create_default_endpoints();
1976
-
1977
- // Exclude the typescript output directory from the file watcher.
1978
- // if (this.ts.output) {
1979
- // this.file_watcher!.add_exclude(this.ts.output);
1980
- // }
1981
-
1982
- // Add the volt backend source files to the additional files.
1983
- this.file_watcher!.add_path(__dirname);
1984
- this.file_watcher!.add_exclude(`${__dirname}/frontend_globals.js`);
1985
-
1986
- // Excluded.
1987
- this.file_watcher!.add_exclude(this.source.join(".db"));
1988
- this.file_watcher!.add_exclude(this.source.join(".rate_limit"));
1989
- this.file_watcher!.add_exclude(this.source.join(".logs"));
1990
-
1991
- // Exclude static files.
1992
- this.statics.forEach(item => {
1993
- if (typeof item === "string" || item instanceof vlib.Path) {
1994
- this.file_watcher!.add_exclude(item);
1995
- }
1996
- else {
1997
- this.file_watcher!.add_exclude(item.path)
1998
- }
1999
- })
2000
-
2001
- if (!this.production) {
2002
- [
2003
- `${process.env.PERSISTANCE}/private/dev/vinc/vlib/js/vlib.js`,
2004
- `${process.env.PERSISTANCE}/private/dev/vinc/vhighlight/vhighlight.js`,
2005
- ].forEach(path => {
2006
- const vpath = new vlib.Path(path);
2007
- if (vpath.exists()) {
2008
- this.file_watcher!.add_exclude(vpath.str());
2009
- }
2010
- })
2011
- }
1984
+ // // Create default endpoints for excluded static file watch paths.
1985
+ // this._create_default_endpoints();
1986
+
1987
+ // // Exclude the typescript output directory from the file watcher.
1988
+ // // if (this.ts.output) {
1989
+ // // this.file_watcher!.add_exclude(this.ts.output);
1990
+ // // }
1991
+
1992
+ // // Add the volt backend source files to the additional files.
1993
+ // this.file_watcher!.add_path(__dirname);
1994
+ // this.file_watcher!.add_exclude(`${__dirname}/frontend_globals.js`);
1995
+
1996
+ // // Exclude static files.
1997
+ // this.statics.forEach(item => {
1998
+ // if (typeof item === "string" || item instanceof vlib.Path) {
1999
+ // this.file_watcher!.add_exclude(item);
2000
+ // }
2001
+ // else {
2002
+ // this.file_watcher!.add_exclude(item.path)
2003
+ // }
2004
+ // })
2005
+
2006
+ // if (!this.production) {
2007
+ // [
2008
+ // `${process.env.PERSISTANCE}/private/dev/vinc/vlib/js/vlib.js`,
2009
+ // `${process.env.PERSISTANCE}/private/dev/vinc/vhighlight/vhighlight.js`,
2010
+ // ].forEach(path => {
2011
+ // const vpath = new vlib.Path(path);
2012
+ // if (vpath.exists()) {
2013
+ // this.file_watcher!.add_exclude(vpath.str());
2014
+ // }
2015
+ // })
2016
+ // }
2017
+
2018
+ // // Stop.
2019
+ // return;
2020
+ // }
2012
2021
 
2013
- // Stop.
2014
- return;
2015
- }
2022
+ // // No file watcher.
2023
+ // else {
2016
2024
 
2017
- // No file watcher.
2018
- else {
2019
2025
  // Create HTTPS server.
2020
2026
  if (this.tls) {
2021
2027
  this.https = http2.createSecureServer(
@@ -2057,10 +2063,8 @@ export class Server {
2057
2063
  }
2058
2064
 
2059
2065
  /* @performance */ this.performance.end("create-http-server");
2060
- }
2061
-
2062
- // No file watcher.
2063
- const file_watcher_restart = process.argv.includes("--file-watcher-restart");
2066
+
2067
+ // }
2064
2068
 
2065
2069
  // Start the database.
2066
2070
  if (this.db) {
@@ -2440,11 +2444,11 @@ export class Server {
2440
2444
  await this.initialize();
2441
2445
 
2442
2446
  // Inside file watcher process.
2443
- if (this.is_file_watcher) {
2444
- this.file_watcher!.start();
2445
- await this.file_watcher!.promise;
2446
- return ;
2447
- }
2447
+ // if (this.is_file_watcher) {
2448
+ // this.file_watcher!.start();
2449
+ // await this.file_watcher!.promise;
2450
+ // return ;
2451
+ // }
2448
2452
 
2449
2453
  // Start static file watcher.
2450
2454
  // if (!this.production && this.file_watcher) {
@@ -2540,25 +2544,15 @@ export class Server {
2540
2544
  // worker.start();
2541
2545
  // }
2542
2546
 
2543
- // Set default port.
2544
- let http_port: number, https_port: number;
2545
- if (this.port == null) {
2546
- http_port = 80;
2547
- https_port = 443;
2548
- } else {
2549
- http_port = this.port;
2550
- https_port = this.port + 1;
2551
- }
2552
-
2553
2547
  // Callbacks.
2554
2548
  let is_running = false;
2555
2549
  const on_running = () => {
2556
2550
  if (!is_running) {
2557
2551
  is_running = true;
2558
2552
  if (this.https !== undefined) {
2559
- logger.log(0, log_source, `Running on http://${this.ip}:${http_port} and https://${this.ip}:${https_port}.`);
2553
+ logger.log(0, log_source, `Running on http://${this.ip}:${this.port} and https://${this.ip}:${this.https_port}.`);
2560
2554
  } else {
2561
- logger.log(0, log_source, `Running on http://${this.ip}:${http_port}.`);
2555
+ logger.log(0, log_source, `Running on http://${this.ip}:${this.port}.`);
2562
2556
  }
2563
2557
  }
2564
2558
  };
@@ -2581,10 +2575,10 @@ export class Server {
2581
2575
  };
2582
2576
 
2583
2577
  // Listen.
2584
- this.http.listen(http_port, this.ip, on_running);
2578
+ this.http.listen(this.port, this.ip, on_running);
2585
2579
  this.http.on("error", on_error);
2586
2580
  if (this.https !== undefined) {
2587
- this.https.listen(https_port, this.ip, on_running);
2581
+ this.https.listen(this.https_port, this.ip, on_running);
2588
2582
  this.https.on("error", on_error);
2589
2583
  }
2590
2584
 
@@ -2952,12 +2946,13 @@ export class Server {
2952
2946
 
2953
2947
  // Add endpoint.
2954
2948
  this.endpoints.set(`${endpoint.endpoint}:${endpoint.method}`, endpoint);
2955
- if (!this.production) {
2956
- if (endpoint._path && this.file_watcher?.add_exclude) {
2957
- this.file_watcher!.add_exclude(endpoint._path);
2958
- }
2959
- // this.static_file_watcher.add(endpoint);
2960
- }
2949
+
2950
+ // if (!this.production) {
2951
+ // if (endpoint._path && this.file_watcher?.add_exclude) {
2952
+ // this.file_watcher!.add_exclude(endpoint._path);
2953
+ // }
2954
+ // // this.static_file_watcher.add(endpoint);
2955
+ // }
2961
2956
  }
2962
2957
  return this;
2963
2958
  }
@@ -18,7 +18,7 @@ export * from "./server.js"
18
18
  export * from "./database.js"
19
19
  export * from "./rate_limit.js"
20
20
  export * from "./logger.js"
21
- export * from "./file_watcher.js"
21
+ // export * from "./file_watcher.js"
22
22
  export * as Mail from "./plugins/mail.js"
23
23
  // export * as PDF from "./plugins/pdf.js"
24
24
  export * as TypeScript from "./plugins/ts/compiler.js"
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "author": "Daan van den Bergh",
3
3
  "name": "@vandenberghinc/volt",
4
- "version": "1.1.7",
4
+ "version": "1.1.9",
5
5
  "description": "",
6
6
  "type": "module",
7
7
  "types": "./backend/dist/esm/volt.d.ts",