@vandenberghinc/volt 1.1.4 → 1.1.6

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.
Files changed (290) hide show
  1. package/backend/dist/cjs/database.d.ts +41 -68
  2. package/backend/dist/cjs/database.js +136 -78
  3. package/backend/dist/cjs/endpoint.d.ts +23 -9
  4. package/backend/dist/cjs/endpoint.js +98 -21
  5. package/backend/dist/cjs/file_watcher.js +2 -2
  6. package/backend/dist/cjs/frontend.d.ts +0 -2
  7. package/backend/dist/cjs/frontend.js +9 -9
  8. package/backend/dist/cjs/image_endpoint.d.ts +3 -1
  9. package/backend/dist/cjs/image_endpoint.js +2 -1
  10. package/backend/dist/cjs/payments/paddle.js +10 -2
  11. package/backend/dist/cjs/plugins/css.d.ts +6 -5
  12. package/backend/dist/cjs/plugins/css.js +32 -7
  13. package/backend/dist/cjs/plugins/ts/compiler.d.ts +6 -1
  14. package/backend/dist/cjs/plugins/ts/compiler.js +26 -2
  15. package/backend/dist/cjs/plugins/ts/preprocessing.js +5 -3
  16. package/backend/dist/cjs/server.d.ts +7 -13
  17. package/backend/dist/cjs/server.js +184 -303
  18. package/backend/dist/cjs/status.d.ts +1 -0
  19. package/backend/dist/cjs/status.js +2 -1
  20. package/backend/dist/cjs/stream.d.ts +5 -3
  21. package/backend/dist/cjs/stream.js +13 -4
  22. package/backend/dist/cjs/users.d.ts +1 -1
  23. package/backend/dist/cjs/users.js +87 -72
  24. package/backend/dist/cjs/utils.d.ts +17 -9
  25. package/backend/dist/cjs/utils.js +22 -64
  26. package/backend/dist/cjs/view.d.ts +2 -2
  27. package/backend/dist/cjs/view.js +38 -40
  28. package/backend/dist/cjs/volt.d.ts +3 -2
  29. package/backend/dist/cjs/volt.js +2 -2
  30. package/backend/dist/css/volt.css +5 -0
  31. package/backend/dist/esm/database.d.ts +41 -68
  32. package/backend/dist/esm/database.js +137 -79
  33. package/backend/dist/esm/endpoint.d.ts +23 -9
  34. package/backend/dist/esm/endpoint.js +99 -22
  35. package/backend/dist/esm/file_watcher.js +2 -2
  36. package/backend/dist/esm/frontend.d.ts +0 -2
  37. package/backend/dist/esm/frontend.js +9 -9
  38. package/backend/dist/esm/image_endpoint.d.ts +3 -1
  39. package/backend/dist/esm/image_endpoint.js +2 -1
  40. package/backend/dist/esm/payments/paddle.js +11 -3
  41. package/backend/dist/esm/plugins/css.d.ts +6 -5
  42. package/backend/dist/esm/plugins/css.js +32 -6
  43. package/backend/dist/esm/plugins/ts/compiler.d.ts +6 -1
  44. package/backend/dist/esm/plugins/ts/compiler.js +26 -2
  45. package/backend/dist/esm/plugins/ts/preprocessing.js +5 -3
  46. package/backend/dist/esm/server.d.ts +7 -13
  47. package/backend/dist/esm/server.js +182 -301
  48. package/backend/dist/esm/status.d.ts +1 -0
  49. package/backend/dist/esm/status.js +1 -0
  50. package/backend/dist/esm/stream.d.ts +5 -3
  51. package/backend/dist/esm/stream.js +13 -4
  52. package/backend/dist/esm/users.d.ts +1 -1
  53. package/backend/dist/esm/users.js +87 -72
  54. package/backend/dist/esm/utils.d.ts +17 -9
  55. package/backend/dist/esm/utils.js +21 -62
  56. package/backend/dist/esm/view.d.ts +2 -2
  57. package/backend/dist/esm/view.js +38 -40
  58. package/backend/dist/esm/volt.d.ts +3 -2
  59. package/backend/dist/esm/volt.js +2 -1
  60. package/backend/dist/esm-dev/blacklist.js +1 -1
  61. package/backend/dist/esm-dev/cli.js +2 -2
  62. package/backend/dist/esm-dev/database.d.ts +41 -68
  63. package/backend/dist/esm-dev/database.js +138 -80
  64. package/backend/dist/esm-dev/endpoint.d.ts +23 -9
  65. package/backend/dist/esm-dev/endpoint.js +100 -23
  66. package/backend/dist/esm-dev/file_watcher.js +3 -3
  67. package/backend/dist/esm-dev/frontend.d.ts +0 -2
  68. package/backend/dist/esm-dev/frontend.js +9 -9
  69. package/backend/dist/esm-dev/image_endpoint.d.ts +3 -1
  70. package/backend/dist/esm-dev/image_endpoint.js +2 -1
  71. package/backend/dist/esm-dev/logger.js +1 -1
  72. package/backend/dist/esm-dev/payments/paddle.js +12 -4
  73. package/backend/dist/esm-dev/plugins/css.d.ts +6 -5
  74. package/backend/dist/esm-dev/plugins/css.js +33 -7
  75. package/backend/dist/esm-dev/plugins/ts/compiler.d.ts +6 -1
  76. package/backend/dist/esm-dev/plugins/ts/compiler.js +27 -3
  77. package/backend/dist/esm-dev/plugins/ts/preprocessing.js +7 -5
  78. package/backend/dist/esm-dev/rate_limit.js +1 -1
  79. package/backend/dist/esm-dev/server.d.ts +7 -13
  80. package/backend/dist/esm-dev/server.js +184 -303
  81. package/backend/dist/esm-dev/status.d.ts +1 -0
  82. package/backend/dist/esm-dev/status.js +1 -0
  83. package/backend/dist/esm-dev/stream.d.ts +5 -3
  84. package/backend/dist/esm-dev/stream.js +13 -4
  85. package/backend/dist/esm-dev/users.d.ts +1 -1
  86. package/backend/dist/esm-dev/users.js +88 -73
  87. package/backend/dist/esm-dev/utils.d.ts +17 -9
  88. package/backend/dist/esm-dev/utils.js +22 -63
  89. package/backend/dist/esm-dev/view.d.ts +2 -2
  90. package/backend/dist/esm-dev/view.js +39 -41
  91. package/backend/dist/esm-dev/volt.d.ts +3 -2
  92. package/backend/dist/esm-dev/volt.js +2 -1
  93. package/backend/src/database.ts +173 -155
  94. package/backend/src/endpoint.ts +123 -31
  95. package/backend/src/file_watcher.ts +2 -2
  96. package/backend/src/frontend.ts +9 -8
  97. package/backend/src/image_endpoint.ts +4 -0
  98. package/backend/src/payments/paddle.ts +11 -3
  99. package/backend/src/plugins/css.ts +36 -8
  100. package/backend/src/plugins/ts/compiler.ts +37 -1
  101. package/backend/src/plugins/ts/preprocessing.ts +5 -3
  102. package/backend/src/server.ts +167 -306
  103. package/backend/src/status.ts +1 -0
  104. package/backend/src/stream.ts +28 -8
  105. package/backend/src/users.ts +87 -72
  106. package/backend/src/utils.ts +58 -25
  107. package/backend/src/view.ts +30 -28
  108. package/backend/src/{volt.js → volt.ts} +2 -1
  109. package/backend/tsconfig.cjs.json +3 -3
  110. package/backend/tsconfig.esm.json +3 -3
  111. package/frontend/dist/elements/base.d.ts +414 -432
  112. package/frontend/dist/elements/base.js +566 -329
  113. package/frontend/dist/elements/module.d.ts +26 -12
  114. package/frontend/dist/elements/module.js +69 -32
  115. package/frontend/dist/elements/register_element.d.ts +3 -0
  116. package/frontend/dist/elements/register_element.js +22 -0
  117. package/frontend/dist/modules/auth.d.ts +1 -0
  118. package/frontend/dist/modules/auth.js +6 -5
  119. package/frontend/dist/modules/color.d.ts +159 -0
  120. package/frontend/dist/modules/color.js +315 -0
  121. package/frontend/dist/modules/colors.d.ts +1 -26
  122. package/frontend/dist/modules/colors.js +417 -340
  123. package/frontend/dist/modules/cookies.d.ts +1 -0
  124. package/frontend/dist/modules/cookies.js +1 -0
  125. package/frontend/dist/modules/events.d.ts +1 -0
  126. package/frontend/dist/modules/events.js +1 -0
  127. package/frontend/dist/modules/google.d.ts +1 -0
  128. package/frontend/dist/modules/google.js +1 -0
  129. package/frontend/dist/modules/meta.d.ts +1 -0
  130. package/frontend/dist/modules/meta.js +1 -0
  131. package/frontend/dist/modules/mutex.d.ts +1 -2
  132. package/frontend/dist/modules/mutex.js +3 -4
  133. package/frontend/dist/modules/paddle.d.ts +1 -0
  134. package/frontend/dist/modules/paddle.js +14 -13
  135. package/frontend/dist/modules/scheme.d.ts +1 -0
  136. package/frontend/dist/modules/scheme.js +5 -3
  137. package/frontend/dist/modules/statics.d.ts +1 -0
  138. package/frontend/dist/modules/statics.js +1 -0
  139. package/frontend/dist/modules/support.d.ts +1 -0
  140. package/frontend/dist/modules/support.js +3 -2
  141. package/frontend/dist/modules/theme.d.ts +56 -0
  142. package/frontend/dist/{ui → modules}/theme.js +186 -75
  143. package/frontend/dist/modules/themes.d.ts +1 -1
  144. package/frontend/dist/modules/themes.js +1 -0
  145. package/frontend/dist/modules/user.d.ts +1 -0
  146. package/frontend/dist/modules/user.js +11 -10
  147. package/frontend/dist/modules/utils.d.ts +23 -2
  148. package/frontend/dist/modules/utils.js +93 -1
  149. package/frontend/dist/types/gradient.js +4 -0
  150. package/frontend/dist/ui/border_button.d.ts +0 -25
  151. package/frontend/dist/ui/border_button.js +50 -51
  152. package/frontend/dist/ui/button.d.ts +0 -21
  153. package/frontend/dist/ui/button.js +41 -46
  154. package/frontend/dist/ui/canvas.js +15 -15
  155. package/frontend/dist/ui/checkbox.d.ts +3 -17
  156. package/frontend/dist/ui/checkbox.js +36 -30
  157. package/frontend/dist/ui/code.d.ts +15 -82
  158. package/frontend/dist/ui/code.js +150 -125
  159. package/frontend/dist/ui/color.d.ts +0 -1
  160. package/frontend/dist/ui/color.js +1 -1
  161. package/frontend/dist/ui/context_menu.d.ts +4 -2
  162. package/frontend/dist/ui/context_menu.js +16 -17
  163. package/frontend/dist/ui/css.js +2 -0
  164. package/frontend/dist/ui/divider.d.ts +0 -7
  165. package/frontend/dist/ui/divider.js +21 -25
  166. package/frontend/dist/ui/dropdown.d.ts +13 -7
  167. package/frontend/dist/ui/dropdown.js +65 -30
  168. package/frontend/dist/ui/for_each.d.ts +0 -5
  169. package/frontend/dist/ui/for_each.js +17 -22
  170. package/frontend/dist/ui/form.d.ts +17 -12
  171. package/frontend/dist/ui/form.js +21 -18
  172. package/frontend/dist/ui/frame_modes.d.ts +9 -12
  173. package/frontend/dist/ui/frame_modes.js +8 -10
  174. package/frontend/dist/ui/google_map.d.ts +0 -11
  175. package/frontend/dist/ui/google_map.js +23 -28
  176. package/frontend/dist/ui/gradient.d.ts +0 -5
  177. package/frontend/dist/ui/gradient.js +17 -22
  178. package/frontend/dist/ui/image.d.ts +27 -58
  179. package/frontend/dist/ui/image.js +99 -93
  180. package/frontend/dist/ui/input.d.ts +20 -97
  181. package/frontend/dist/ui/input.js +192 -170
  182. package/frontend/dist/ui/link.d.ts +0 -18
  183. package/frontend/dist/ui/link.js +42 -48
  184. package/frontend/dist/ui/list.js +36 -37
  185. package/frontend/dist/ui/loader_button.d.ts +4 -19
  186. package/frontend/dist/ui/loader_button.js +35 -37
  187. package/frontend/dist/ui/loaders.d.ts +0 -8
  188. package/frontend/dist/ui/loaders.js +20 -25
  189. package/frontend/dist/ui/popup.d.ts +11 -8
  190. package/frontend/dist/ui/popup.js +183 -24
  191. package/frontend/dist/ui/pseudo.d.ts +3 -3
  192. package/frontend/dist/ui/pseudo.js +14 -17
  193. package/frontend/dist/ui/scroller.d.ts +10 -48
  194. package/frontend/dist/ui/scroller.js +306 -300
  195. package/frontend/dist/ui/slider.d.ts +9 -3
  196. package/frontend/dist/ui/slider.js +31 -17
  197. package/frontend/dist/ui/spacer.d.ts +0 -9
  198. package/frontend/dist/ui/spacer.js +21 -26
  199. package/frontend/dist/ui/span.js +13 -15
  200. package/frontend/dist/ui/stack.d.ts +14 -75
  201. package/frontend/dist/ui/stack.js +166 -169
  202. package/frontend/dist/ui/steps.d.ts +10 -23
  203. package/frontend/dist/ui/steps.js +47 -34
  204. package/frontend/dist/ui/style.d.ts +4 -3
  205. package/frontend/dist/ui/style.js +13 -18
  206. package/frontend/dist/ui/switch.d.ts +10 -4
  207. package/frontend/dist/ui/switch.js +24 -16
  208. package/frontend/dist/ui/table.d.ts +0 -23
  209. package/frontend/dist/ui/table.js +113 -119
  210. package/frontend/dist/ui/tabs.d.ts +3 -19
  211. package/frontend/dist/ui/tabs.js +35 -29
  212. package/frontend/dist/ui/text.d.ts +0 -8
  213. package/frontend/dist/ui/text.js +20 -25
  214. package/frontend/dist/ui/title.d.ts +0 -15
  215. package/frontend/dist/ui/title.js +39 -45
  216. package/frontend/dist/ui/ui.d.ts +0 -2
  217. package/frontend/dist/ui/ui.js +0 -2
  218. package/frontend/dist/ui/view.d.ts +3 -17
  219. package/frontend/dist/ui/view.js +27 -32
  220. package/frontend/dist/volt.d.ts +2 -1
  221. package/frontend/dist/volt.js +3 -1
  222. package/frontend/examples/dashboard/dashboard.ts +774 -0
  223. package/frontend/examples/theme/theme.ts +58 -0
  224. package/frontend/src/css/volt.css +5 -0
  225. package/frontend/src/elements/base.ts +767 -545
  226. package/frontend/src/elements/module.ts +90 -29
  227. package/frontend/src/elements/register_element.ts +24 -0
  228. package/frontend/src/modules/auth.ts +7 -6
  229. package/frontend/src/modules/color.ts +348 -0
  230. package/frontend/src/modules/colors.ts +468 -449
  231. package/frontend/src/modules/cookies.ts +1 -0
  232. package/frontend/src/modules/events.ts +1 -0
  233. package/frontend/src/modules/google.ts +1 -0
  234. package/frontend/src/modules/meta.ts +2 -1
  235. package/frontend/src/modules/mutex.ts +2 -4
  236. package/frontend/src/modules/paddle.ts +21 -20
  237. package/frontend/src/modules/scheme.ts +5 -4
  238. package/frontend/src/modules/statics.ts +2 -1
  239. package/frontend/src/modules/support.ts +3 -2
  240. package/frontend/src/modules/theme.ts +413 -0
  241. package/frontend/src/modules/themes.ts +2 -1
  242. package/frontend/src/modules/user.ts +12 -11
  243. package/frontend/src/modules/utils.ts +125 -2
  244. package/frontend/src/ui/border_button.ts +41 -37
  245. package/frontend/src/ui/button.ts +33 -32
  246. package/frontend/src/ui/canvas.ts +5 -2
  247. package/frontend/src/ui/checkbox.ts +21 -22
  248. package/frontend/src/ui/code.ts +92 -86
  249. package/frontend/src/ui/context_menu.ts +7 -5
  250. package/frontend/src/ui/css.ts +1 -1
  251. package/frontend/src/ui/divider.ts +15 -10
  252. package/frontend/src/ui/dropdown.ts +38 -21
  253. package/frontend/src/ui/for_each.ts +9 -8
  254. package/frontend/src/ui/form.ts +26 -21
  255. package/frontend/src/ui/frame_modes.ts +13 -17
  256. package/frontend/src/ui/google_map.ts +15 -13
  257. package/frontend/src/ui/gradient.ts +9 -8
  258. package/frontend/src/ui/image.ts +108 -86
  259. package/frontend/src/ui/input.ts +145 -144
  260. package/frontend/src/ui/link.ts +25 -23
  261. package/frontend/src/ui/list.ts +12 -6
  262. package/frontend/src/ui/loader_button.ts +26 -25
  263. package/frontend/src/ui/loaders.ts +12 -11
  264. package/frontend/src/ui/popup.ts +168 -14
  265. package/frontend/src/ui/pseudo.ts +5 -3
  266. package/frontend/src/ui/scroller.ts +303 -294
  267. package/frontend/src/ui/slider.ts +15 -10
  268. package/frontend/src/ui/spacer.ts +14 -11
  269. package/frontend/src/ui/span.ts +6 -2
  270. package/frontend/src/ui/stack.ts +196 -183
  271. package/frontend/src/ui/steps.ts +38 -22
  272. package/frontend/src/ui/style.ts +7 -4
  273. package/frontend/src/ui/switch.ts +16 -11
  274. package/frontend/src/ui/table.ts +42 -34
  275. package/frontend/src/ui/tabs.ts +20 -19
  276. package/frontend/src/ui/text.ts +12 -11
  277. package/frontend/src/ui/title.ts +22 -20
  278. package/frontend/src/ui/ui.ts +0 -2
  279. package/frontend/src/ui/view.ts +20 -19
  280. package/frontend/src/volt.ts +3 -1
  281. package/frontend/{compile.js → tools/compile.old.js} +2 -2
  282. package/frontend/tools/embed_scripts.js +69 -0
  283. package/frontend/tsconfig.json +26 -0
  284. package/package.json +7 -6
  285. package/frontend/dist/ui/theme.d.ts +0 -25
  286. package/frontend/exports.json +0 -1340
  287. package/frontend/src/modules/date.js +0 -535
  288. package/frontend/src/ui/color.ts +0 -117
  289. package/frontend/src/ui/theme.ts +0 -279
  290. /package/backend/src/{vinc.dev.js → vinc.dev.ts} +0 -0
@@ -20,7 +20,7 @@ import CleanCSS from 'clean-css';
20
20
 
21
21
  import { vlib } from "@vinc";
22
22
  import { vhighlight } from "@vinc";
23
- import { Utils, FrontendError } from "./utils.js";
23
+ import { Utils, APIError } from "./utils.js";
24
24
  import { Meta } from './meta.js';
25
25
  import * as Mail from './plugins/mail.js';
26
26
  import { Status } from "./status.js";
@@ -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";
@@ -37,7 +37,7 @@ import { Blacklist } from "./blacklist.js";
37
37
  import logger, { LogSource } from "./logger.js";
38
38
  import * as TSCompiler from "./plugins/ts/compiler.js";
39
39
  import * as TSPreprocessing from "./plugins/ts/preprocessing.js";
40
- import { BrowserPreview } from "./plugins/browser.js";
40
+ // import { BrowserPreview } from "./plugins/browser.js";
41
41
 
42
42
  const log_source = new LogSource("Server");
43
43
 
@@ -163,6 +163,10 @@ interface DatabaseCollections {}
163
163
  @description: Whether the server is in production more, or in development mode.
164
164
  @type: boolean
165
165
  @required: true
166
+ @parameter:
167
+ @name: localhost
168
+ @description: Wether to run on localhost. This overrides the given `ip` parameter, and makes the `ip` parameter optional.
169
+ @type: boolean
166
170
  @parameter:
167
171
  @name: ip
168
172
  @description: The ip where the server will run on.
@@ -621,6 +625,7 @@ export class Server {
621
625
  [".jpeg", "image/jpeg"],
622
626
  [".jpg", "image/jpeg"],
623
627
  [".js", "application/javascript"],
628
+ [".ts", "application/javascript"],
624
629
  [".atom", "application/atom+xml"],
625
630
  [".rss", "application/rss+xml"],
626
631
  [".mml", "text/mathml"],
@@ -703,7 +708,7 @@ export class Server {
703
708
  [".ra", "audio/x-realaudio"],
704
709
  [".3gpp", "video/3gpp"],
705
710
  [".3gp", "video/3gpp"],
706
- [".ts", "video/mp2t"],
711
+ // [".ts", "video/mp2t"],
707
712
  [".mp4", "video/mp4"],
708
713
  [".mpeg", "video/mpeg"],
709
714
  [".mpg", "video/mpeg"],
@@ -776,6 +781,7 @@ export class Server {
776
781
  public token_expiration: number;
777
782
  public google_tag?: string;
778
783
  public production: boolean;
784
+ public localhost: boolean;
779
785
  public multiprocessing: boolean;
780
786
  public processes: number;
781
787
  public company: CompanyInfo;
@@ -789,8 +795,11 @@ export class Server {
789
795
  public log_level: number;
790
796
  public tls?: TLSConfig;
791
797
  public file_watcher?: FileWatcher;
792
- public admin: AdminConfig;
793
- public ts: TypeScriptConfig;
798
+ // public admin: AdminConfig;
799
+ // public ts: TypeScriptConfig;
800
+ public lightweight: boolean;
801
+
802
+
794
803
  public performance: vlib.Performance;
795
804
  public csp: Record<string, string>;
796
805
  public default_headers: Record<string, string>;
@@ -809,8 +818,8 @@ export class Server {
809
818
  public keys: Record<string, string>;
810
819
  private _on_start: Array<(args: {forked: boolean}) => void | Promise<void>>;
811
820
  private _on_stop: Array<() => void | Promise<void>>;
812
- public browser_preview?: BrowserPreview;
813
- public static_file_watcher: StaticFileWatcher;
821
+ // public browser_preview?: BrowserPreview;
822
+ // public static_file_watcher: StaticFileWatcher;
814
823
  public is_file_watcher: boolean;
815
824
  public daemon?: vlib.Daemon;
816
825
  private _stop_tscompiler_watcher?: () => void;
@@ -869,22 +878,24 @@ export class Server {
869
878
  enable_account_activation = true,
870
879
  // honey_pot_key = null,
871
880
  production = false,
881
+ localhost = true,
872
882
  multiprocessing = true,
873
883
  processes = null,
874
- file_watcher = {},
884
+ file_watcher = false,
875
885
  offline = false,
876
886
  additional_sitemap_endpoints = [],
877
887
  log_level = 0,
878
888
  daemon = {},
879
- admin = {
880
- password: null,
881
- ips: [],
882
- },
883
- ts = {
884
- compiler_opts: {},
885
- output: undefined,
886
- },
887
- browser_preview = undefined,
889
+ // admin = {
890
+ // password: null,
891
+ // ips: [],
892
+ // },
893
+ // ts = {
894
+ // compiler_opts: {},
895
+ // output: undefined,
896
+ // },
897
+ // browser_preview = undefined,
898
+ lightweight = false,
888
899
  }: {
889
900
  ip?: string;
890
901
  port?: number;
@@ -899,7 +910,7 @@ export class Server {
899
910
  tls?: TLSConfig;
900
911
  smtp?: nodemailer.TransportOptions;
901
912
  mail_style?: Partial<MailStyle>;
902
- rate_limit?: RateLimitConfig;
913
+ rate_limit?: false | RateLimitConfig;
903
914
  keys?: Array<string | {name: string, length: number}>;
904
915
  payments?: any;
905
916
  default_headers?: Record<string, any> | null;
@@ -909,6 +920,7 @@ export class Server {
909
920
  enable_account_activation?: boolean;
910
921
  // honey_pot_key?: string | null;
911
922
  production?: boolean;
923
+ localhost?: boolean;
912
924
  multiprocessing?: boolean;
913
925
  processes?: number | null;
914
926
  file_watcher?: FileWatcher | Record<string, any> | boolean;
@@ -916,9 +928,10 @@ export class Server {
916
928
  additional_sitemap_endpoints?: string[];
917
929
  log_level?: number;
918
930
  daemon?: Record<string, any> | boolean;
919
- admin?: Partial<AdminConfig>;
920
- ts?: Partial<TypeScriptConfig>;
921
- browser_preview?: string;
931
+ // admin?: Partial<AdminConfig>;
932
+ // ts?: Partial<TypeScriptConfig>;
933
+ // browser_preview?: string;
934
+ lightweight?: boolean,
922
935
  }) {
923
936
 
924
937
  // @debug
@@ -958,8 +971,8 @@ export class Server {
958
971
 
959
972
  // Verify args.
960
973
  vlib.Scheme.verify({object: arguments[0], err_prefix: "Server: ", check_unknown: true, scheme: {
961
- ip: "string",
962
- port: "number",
974
+ ip: { type: "string", required: false },
975
+ port: { type: "number", required: false },
963
976
  domain: "string",
964
977
  statics: {type: "array", default: []},
965
978
  is_primary: {type: "boolean", default: true},
@@ -1003,11 +1016,8 @@ export class Server {
1003
1016
  }
1004
1017
  },
1005
1018
  rate_limit: {
1006
- type: "object",
1007
- default: {
1008
- ip: null,
1009
- port: RateLimitServer.default_port,
1010
- },
1019
+ type: ["boolean", "object"],
1020
+ default: false,
1011
1021
  scheme: {
1012
1022
  server: {type: "object", default: {}, scheme: {
1013
1023
  ip: {type: "string", default: null},
@@ -1047,6 +1057,7 @@ export class Server {
1047
1057
  enable_2fa: {type: "boolean", required: false},
1048
1058
  enable_account_activation: {type: "boolean", required: false},
1049
1059
  production: {type: "boolean", required: false},
1060
+ localhost: { type: "boolean", required: false },
1050
1061
  multiprocessing: {type: "boolean", required: false, default: true},
1051
1062
  processes: {type: "number", required: false, default: null},
1052
1063
  file_watcher: {type: ["null", "boolean", "object", FileWatcher], required: false},
@@ -1054,22 +1065,23 @@ export class Server {
1054
1065
  additional_sitemap_endpoints: {type: "array", default: []},
1055
1066
  log_level: {type: "number", default: 0},
1056
1067
  daemon: {type: ["object", "boolean"], default: {}},
1057
- admin: {type: "object", default: {}, attributes: {
1058
- ips: {type: "array", default: []},
1059
- password: {
1060
- type: "string",
1061
- verify: (param: string, attrs) => (param.length < 10 ? `Parameter "Server.admin.password" must have a length of at least 10 characters.` : undefined),
1062
- },
1063
- }},
1064
- ts: {
1065
- type: "object",
1066
- required: false,
1067
- scheme: {
1068
- compiler_opts: {type: "object", default: {}},
1069
- output: "string",
1070
- },
1071
- },
1072
- browser_preview: {type: "string", required: false, default: undefined},
1068
+ // admin: {type: "object", default: {}, attributes: {
1069
+ // ips: {type: "array", default: []},
1070
+ // password: {
1071
+ // type: "string",
1072
+ // verify: (param: string, attrs) => (param.length < 10 ? `Parameter "Server.admin.password" must have a length of at least 10 characters.` : undefined),
1073
+ // },
1074
+ // }},
1075
+ // ts: {
1076
+ // type: "object",
1077
+ // required: false,
1078
+ // scheme: {
1079
+ // compiler_opts: {type: "object", default: {}},
1080
+ // output: "string",
1081
+ // },
1082
+ // },
1083
+ // browser_preview: {type: ["string", "undefined"], required: false, default: undefined},
1084
+ lightweight: {type: "boolean", required: false},
1073
1085
  }});
1074
1086
 
1075
1087
  // Assign attributes directly.
@@ -1083,6 +1095,8 @@ export class Server {
1083
1095
  this.token_expiration = token_expiration;
1084
1096
  this.google_tag = google_tag;
1085
1097
  this.production = production;
1098
+ this.localhost = localhost;
1099
+ this.lightweight = lightweight;
1086
1100
  this.multiprocessing = multiprocessing;
1087
1101
  this.processes = processes == null ? os.cpus().length : processes;
1088
1102
  this.company = company;
@@ -1095,11 +1109,17 @@ export class Server {
1095
1109
  this.log_level = log_level;
1096
1110
  this.tls = tls;
1097
1111
  // this.file_watcher = file_watcher;
1098
- this.admin = admin as AdminConfig;
1099
- this.ts = ts as TypeScriptConfig;
1112
+ // this.admin = admin as AdminConfig;
1113
+ // this.ts = ts as TypeScriptConfig;
1100
1114
  this.endpoints = new Map();
1101
1115
  this.err_endpoints = new Map();
1102
1116
 
1117
+ // 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
+ }
1122
+
1103
1123
  /* @performance */ this.performance = new vlib.Performance("Server performance");
1104
1124
 
1105
1125
  // Assign objects to server so it is easy to access.
@@ -1211,15 +1231,16 @@ export class Server {
1211
1231
  this.err_endpoints = new Map();
1212
1232
 
1213
1233
  // Browser preview.
1214
- if (browser_preview) {
1215
- this.browser_preview = new BrowserPreview(browser_preview);
1216
- }
1234
+ // if (browser_preview) {
1235
+ // this.browser_preview = new BrowserPreview(browser_preview);
1236
+ // }
1217
1237
 
1218
1238
  // Static file watcher.
1219
- this.static_file_watcher = new StaticFileWatcher(this);
1239
+ // this.static_file_watcher = new StaticFileWatcher(this);
1220
1240
 
1221
1241
  // Initialize file watcher.
1222
1242
  if (file_watcher !== false) {
1243
+ console.warn("[Volt] Argument file_watcher is deprecated. This may be removed in future versions.");
1223
1244
  if (file_watcher == null) {
1224
1245
  // Null.
1225
1246
  file_watcher = {};
@@ -1304,13 +1325,15 @@ export class Server {
1304
1325
  }
1305
1326
 
1306
1327
  // The rate limit server/client.
1307
- if (this.is_primary) {
1308
- this.rate_limit = new RateLimitServer({...(rate_limit.server ?? {}), _server: this});
1309
- } else {
1310
- if (rate_limit.server?.https) {
1311
- (rate_limit.client as Record<string, any>).https = true;
1328
+ if (rate_limit) {
1329
+ if (this.is_primary) {
1330
+ this.rate_limit = new RateLimitServer({...(rate_limit.server ?? {}), _server: this});
1331
+ } else {
1332
+ if (rate_limit.server?.https) {
1333
+ (rate_limit.client as Record<string, any>).https = true;
1334
+ }
1335
+ this.rate_limit = new RateLimitClient({...(rate_limit.client ?? {}), _server: this});
1312
1336
  }
1313
- this.rate_limit = new RateLimitClient({...(rate_limit.client ?? {}), _server: this});
1314
1337
  }
1315
1338
 
1316
1339
  // Blacklist class.
@@ -1435,13 +1458,14 @@ export class Server {
1435
1458
  if (favicon.exists() === false) {
1436
1459
  throw Error(`Specified favicon path "${favicon}" does not exist.`);
1437
1460
  }
1438
- this.endpoint(new Endpoint({
1461
+ this.endpoint({
1439
1462
  method: "GET",
1440
1463
  endpoint: "/favicon.ico",
1441
1464
  data: favicon.load_sync({type: "buffer"}),
1442
1465
  content_type: this.get_content_type(favicon.extension()),
1443
1466
  _is_static: true,
1444
- }))
1467
+ _server: this,
1468
+ })
1445
1469
  // additional_file_watcher_paths.push(favicon.str());
1446
1470
  }
1447
1471
 
@@ -1456,13 +1480,14 @@ export class Server {
1456
1480
  } else {
1457
1481
  status_key = status_key_path.load_sync();
1458
1482
  }
1459
- this.endpoint(new Endpoint({
1483
+ this.endpoint({
1460
1484
  method: "GET",
1461
1485
  endpoint: "/.status",
1462
1486
  content_type: "application/json",
1463
1487
  params: {
1464
1488
  key: "string",
1465
1489
  },
1490
+ _server: this,
1466
1491
  callback: async (stream: any, params: {key: string}) => {
1467
1492
  // Check key.
1468
1493
  if (params.key !== status_key) {
@@ -1500,7 +1525,7 @@ export class Server {
1500
1525
  data: status,
1501
1526
  })
1502
1527
  },
1503
- }))
1528
+ })
1504
1529
 
1505
1530
  // Default static endpoints.
1506
1531
  const defaults = [
@@ -1532,6 +1557,7 @@ export class Server {
1532
1557
  compress: (item as any).compress,
1533
1558
  _path: item.path.str(),
1534
1559
  _templates: (item as any).templates,
1560
+ _server: this,
1535
1561
  })
1536
1562
  ._load_data_by_path(this)
1537
1563
  )
@@ -1543,6 +1569,11 @@ export class Server {
1543
1569
 
1544
1570
  // Create the sitemap endpoint.
1545
1571
  private _create_sitemap(): void {
1572
+
1573
+ // Logs.
1574
+ if (this.lightweight) { return; }
1575
+ logger.log(2, log_source, "Creating sitemap.");
1576
+
1546
1577
  let sitemap = "";
1547
1578
  sitemap += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
1548
1579
  sitemap += "<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n";
@@ -1558,17 +1589,23 @@ export class Server {
1558
1589
  sitemap += `<url>\n <loc>${this.full_domain}/${endpoint}</loc>\n</url>\n`;
1559
1590
  })
1560
1591
  sitemap += "</urlset>\n";
1561
- this.endpoint(new Endpoint({
1592
+ this.endpoint({
1562
1593
  method: "GET",
1563
1594
  endpoint: "/sitemap.xml",
1564
1595
  data: sitemap,
1565
1596
  content_type: "application/xml",
1566
1597
  compress: false,
1567
- }))
1598
+ })
1568
1599
  }
1569
1600
 
1570
1601
  // Create the robots.txt endpoint.
1571
1602
  private _create_robots_txt(): void {
1603
+
1604
+ // Logs.
1605
+ if (this.lightweight) { return; }
1606
+ logger.log(2, log_source, "Creating robots.txt.");
1607
+
1608
+ // Proceed.
1572
1609
  let robots = "User-agent: *\n";
1573
1610
  let disallowed = 0;
1574
1611
  for (const endpoint of this.endpoints.values()) {
@@ -1581,17 +1618,23 @@ export class Server {
1581
1618
  robots += `Disallow: \n`;
1582
1619
  }
1583
1620
  robots += `\nSitemap: ${this.full_domain}/sitemap.xml`;
1584
- this.endpoint(new Endpoint({
1621
+ this.endpoint({
1585
1622
  method: "GET",
1586
1623
  endpoint: "/robots.txt",
1587
1624
  content_type: "text/plain",
1588
1625
  data: robots,
1589
1626
  compress: false,
1590
- }))
1627
+ })
1591
1628
  }
1592
1629
 
1593
1630
  // Create admin endpoint.
1594
- private _create_admin_endpoint(): void {
1631
+ // @deprecated use MongoDB Atlas instead!
1632
+ /* private _create_admin_endpoint(): void {
1633
+
1634
+ // Logs.
1635
+ if (this.lightweight) { return; }
1636
+ logger.log(2, log_source, "Creating admin endpoint.");
1637
+
1595
1638
  // Add admin tokens.
1596
1639
  this.admin.tokens = [];
1597
1640
 
@@ -1613,7 +1656,7 @@ export class Server {
1613
1656
  }
1614
1657
 
1615
1658
  // Admin data.
1616
- this.endpoint(new Endpoint({
1659
+ this.endpoint({
1617
1660
  method: "POST",
1618
1661
  endpoint: "/admin/auth",
1619
1662
  content_type: "application/json",
@@ -1650,10 +1693,10 @@ export class Server {
1650
1693
  data: token,
1651
1694
  })
1652
1695
  },
1653
- }))
1696
+ })
1654
1697
 
1655
1698
  // Admin data.
1656
- this.endpoint(new Endpoint({
1699
+ this.endpoint({
1657
1700
  method: "GET",
1658
1701
  endpoint: "/admin/data",
1659
1702
  content_type: "application/json",
@@ -1704,10 +1747,10 @@ export class Server {
1704
1747
  data: data,
1705
1748
  })
1706
1749
  },
1707
- }))
1750
+ })
1708
1751
 
1709
1752
  // Admin view.
1710
- this.endpoint(new Endpoint({
1753
+ this.endpoint({
1711
1754
  method: "GET",
1712
1755
  endpoint: "/admin",
1713
1756
  content_type: "application/json",
@@ -1736,11 +1779,14 @@ export class Server {
1736
1779
  // ... rest of the admin view implementation remains the same as it's client-side JavaScript ...
1737
1780
  },
1738
1781
  },
1739
- }))
1740
- }
1782
+ })
1783
+ } */
1741
1784
 
1742
1785
  // Initialize statics.
1743
1786
  private async _initialize_statics(): Promise<string[]> {
1787
+
1788
+ // Logs.
1789
+ logger.log(2, log_source, "Initializing static directories.");
1744
1790
 
1745
1791
  // Static paths for the file watcher.
1746
1792
  const static_paths: string[] = [];
@@ -1769,6 +1815,7 @@ export class Server {
1769
1815
  cache,
1770
1816
  rate_limit: "global",
1771
1817
  _is_static: true,
1818
+ _server: this,
1772
1819
  });
1773
1820
  const aspect_ratio = await e.get_aspect_ratio();
1774
1821
  if (aspect_ratio != null) {
@@ -1790,6 +1837,7 @@ export class Server {
1790
1837
  rate_limit: "global",
1791
1838
  _path: path.str(),
1792
1839
  _is_static: true,
1840
+ _server: this,
1793
1841
  })
1794
1842
  ._load_data_by_path(this)
1795
1843
  )
@@ -1906,190 +1954,16 @@ export class Server {
1906
1954
  return static_paths;
1907
1955
  }
1908
1956
 
1909
- // @todo this one is not TS
1910
- // Initialize, compile & bundle js & ts.
1911
- async _init_ts() {
1912
-
1913
- // Create dir.
1914
- // Use ts.output instead of a /tmp/ dir since the node_modules for example is not present here.
1915
- const tmp_volt_ts = new vlib.Path(this.ts.output ?? "/tmp/ts-dummy/").abs();
1916
- if (this.ts.output && !tmp_volt_ts.exists()) {
1917
- tmp_volt_ts.mkdir_sync();
1918
- }
1919
-
1920
- // Gather all entry paths.
1921
- const server = this;
1922
- let has_ts = false;
1923
- const volt_frontend = new vlib.Path(`${__dirname}/../../../frontend/dist/`).abs().str();
1924
- const input_paths: string[] = [
1925
- volt_frontend + "/volt.js",
1926
- ];
1927
- const entries: Record<string, {
1928
- endpoints: Endpoint[],
1929
- path: string,
1930
- extension: string,
1931
- bundle(): Promise<void>;
1932
- }> = {}
1933
- for (const endpoint of this.endpoints.values()) {
1934
- if (endpoint.view?.is_js_ts_view) {
1935
- input_paths.push(endpoint.view.source_path!.str())
1936
- let output_path = tmp_volt_ts.join(endpoint.view.source_path!).abs();
1937
- const extension = output_path.extension();
1938
- if (!has_ts && /.tsx?/.test(extension)) {
1939
- has_ts = true;
1940
- }
1941
- const output = output_path.str().slice(0, -extension.length) + ".js";
1942
- if (entries[output] === undefined) {
1943
- entries[output] = {
1944
- endpoints: [endpoint],
1945
- path: output,
1946
- extension,
1947
- async bundle() {
1948
- server.rate_limit?.reset_all(); // reset api limits.
1949
- let bundle = undefined;
1950
- let had_bundle = this.endpoints[0]?.view?.bundle != null;
1951
- for (let e = 0; e < this.endpoints.length; e++) {
1952
- if (bundle === undefined) {
1953
- bundle = await this.endpoints[e]?.view?._bundle_ts(this.path);
1954
- } else {
1955
- await this.endpoints[e]?.view?._bundle_ts(this.path, bundle);
1956
- }
1957
- if (had_bundle && server.browser_preview) {
1958
- await server.browser_preview.refresh(this.endpoints[e].endpoint);
1959
- }
1960
- }
1961
- },
1962
- };
1963
- } else {
1964
- entries[output].endpoints.push(endpoint);
1965
- }
1966
- }
1967
- }
1968
- const entry_values = Object.values(entries);
1969
- if (has_ts && this.ts.output == null) {
1970
- throw new Error(`Due to detected typescript endpoint source files the output path attribute "Server.ts.output" must be defined.`);
1971
- }
1972
-
1973
- // For production just compile & bundle.
1974
- if (this.is_file_watcher || this.production) {
1975
- await TSCompiler.compile({
1976
- entry_paths: input_paths,
1977
- output: tmp_volt_ts.str(),
1978
- preprocess: TSPreprocessing.volt_auto_imports,
1979
- compiler_opts: {
1980
- target: "ES2021",
1981
- module: "esnext",
1982
- moduleResolution: "node",
1983
- lib: ["ES2021", "DOM"],
1984
- declaration: false,
1985
- strict: true,
1986
- esModuleInterop: true,
1987
- allowJs: true,
1988
- checkJs: false,
1989
- noImplicitAny: false,
1990
- skipLibCheck: true,
1991
- types: [],
1992
- ...this.ts.compiler_opts,
1993
- rootDir: "/", // @warning is required to reliably match input and output file paths.
1994
- },
1995
- })
1996
- let excluded = new Set();
1997
- for (let i = 0; i < entry_values.length; i++) {
1998
- await entry_values[i].bundle();
1999
-
2000
- // Add file watcher excludes.
2001
- if (this.is_file_watcher) {
2002
- for (const endpoint of entry_values[i].endpoints) {
2003
- // console.log(entry_values[i].path, endpoint.view.bundle.inputs)
2004
- for (let path of endpoint.view?.bundle?.inputs ?? []) {
2005
- const vpath = new vlib.Path(path).abs();
2006
- const ext = vpath.extension();
2007
- path = vpath.str();
2008
- if (path.startsWith(tmp_volt_ts.str())) {
2009
- const js_path = path.slice(tmp_volt_ts.str().length);
2010
- const ts_path = path.slice(tmp_volt_ts.str().length, -ext.length) + ".ts";
2011
- if (new vlib.Path(js_path).exists() && !excluded.has(js_path)) {
2012
- // console.log("Exclude", js_path)
2013
- excluded.add(js_path);
2014
- this.file_watcher!.add_exclude(js_path);
2015
- }
2016
- if (new vlib.Path(ts_path).exists() && !excluded.has(ts_path)) {
2017
- // console.log("Exclude", ts_path)
2018
- excluded.add(ts_path);
2019
- this.file_watcher!.add_exclude(ts_path);
2020
- }
2021
- }
2022
- }
2023
- // process.exit(1)
2024
- }
2025
- }
2026
- }
2027
- }
2028
-
2029
- // Development.
2030
- else {
2031
-
2032
- // Compile with watcher enabled.
2033
- const res = await TSCompiler.compile({
2034
- entry_paths: input_paths,
2035
- output: tmp_volt_ts.str(),
2036
- preprocess: TSPreprocessing.volt_auto_imports,
2037
- error_limit: 10,
2038
- compiler_opts: {
2039
- target: "ES2021",
2040
- module: "esnext",
2041
- moduleResolution: "node",
2042
- lib: ["ES2021", "DOM"],
2043
- declaration: false,
2044
- strict: true,
2045
- esModuleInterop: true,
2046
- allowJs: true,
2047
- checkJs: false,
2048
- noImplicitAny: false,
2049
- skipLibCheck: true,
2050
- types: [],
2051
- ...this.ts.compiler_opts,
2052
- rootDir: "/", // @warning is required to reliably match input and output file paths.
2053
- },
2054
- watch: {
2055
- enabled: true,
2056
- log_level: 0,
2057
- on_change: async (file_name) => {
2058
- // console.log("File", file_name, "has changed.")
2059
- logger.log(2, log_source, `Typescript output file ${file_name} has changed.`);
2060
-
2061
- // Check if the file path is part of an endpoint.
2062
- const entry = entries[file_name];
2063
- if (entry != null) {
2064
- await entry.bundle();
2065
- }
2066
-
2067
- // Check every other entries inputs' to see if that entry should be rebundled as well.
2068
- for (let i = 0; i < entry_values.length; i++) {
2069
- const entry = entry_values[i]
2070
- if (entry.path !== file_name && entry.endpoints.iterate(e => e.view?.bundle?.inputs?.includes(file_name) ? true : undefined)) {
2071
- await entry.bundle();
2072
- }
2073
- }
2074
- },
2075
- },
2076
- });
2077
- if (res.errors.length > 0) {
2078
- res.debug();
2079
- }
2080
- for (let i = 0; i < entry_values.length; i++) {
2081
- await entry_values[i].bundle();
2082
- }
2083
- this._stop_tscompiler_watcher = res.stop;
2084
- }
2085
- }
2086
-
2087
1957
  // ---------------------------------------------------------
2088
1958
  // Server (private).
2089
1959
 
2090
1960
  // Initialize.
2091
1961
  // Initialize.
2092
1962
  async initialize(): Promise<void> {
1963
+
1964
+ // Logs.
1965
+ logger.log(1, log_source, "Initializing server.");
1966
+
2093
1967
  /* @performance */ this.performance.start()
2094
1968
 
2095
1969
  // File watcher.
@@ -2101,9 +1975,9 @@ export class Server {
2101
1975
  this._create_default_endpoints();
2102
1976
 
2103
1977
  // Exclude the typescript output directory from the file watcher.
2104
- if (this.ts.output) {
2105
- this.file_watcher!.add_exclude(this.ts.output);
2106
- }
1978
+ // if (this.ts.output) {
1979
+ // this.file_watcher!.add_exclude(this.ts.output);
1980
+ // }
2107
1981
 
2108
1982
  // Add the volt backend source files to the additional files.
2109
1983
  this.file_watcher!.add_path(__dirname);
@@ -2124,17 +1998,6 @@ export class Server {
2124
1998
  }
2125
1999
  })
2126
2000
 
2127
- // Initialize all endpoints since this is required for _init_ts()
2128
- for (const endpoint of this.endpoints.values()) {
2129
- await endpoint._initialize(this);
2130
- }
2131
- for (const endpoint of this.err_endpoints.values()) {
2132
- await endpoint._initialize(this);
2133
- }
2134
-
2135
- // Add typescript/js view endpoint excludes.
2136
- await this._init_ts();
2137
-
2138
2001
  if (!this.production) {
2139
2002
  [
2140
2003
  `${process.env.PERSISTANCE}/private/dev/vinc/vlib/js/vlib.js`,
@@ -2204,10 +2067,10 @@ export class Server {
2204
2067
  await this.db.initialize();
2205
2068
 
2206
2069
  // Database collections.
2207
- this._sys_db = this.db.create_collection("_sys"); // the volt sys collection.
2070
+ this._sys_db = await this.db.create_collection("_sys"); // the volt sys collection.
2208
2071
 
2209
2072
  // Accessible collections.
2210
- this.storage = this.db.create_collection("_storage"); // the sys backend storage collection for the user's server.
2073
+ this.storage = await this.db.create_collection("_storage"); // the sys backend storage collection for the user's server.
2211
2074
 
2212
2075
  /* @performance */ this.performance.end("init-db");
2213
2076
 
@@ -2280,34 +2143,24 @@ export class Server {
2280
2143
  /* @performance */ this.performance.end("create-default-endpoints");
2281
2144
 
2282
2145
  // Create admin endpoints.
2283
- this._create_admin_endpoint();
2284
- /* @performance */ this.performance.end("create-admin-endpoints");
2146
+ // this._create_admin_endpoint();
2147
+ // /* @performance */ this.performance.end("create-admin-endpoints");
2285
2148
 
2286
2149
  // Create static endpoints.
2287
2150
  await this._initialize_statics();
2288
2151
  /* @performance */ this.performance.end("create-static-endpoints");
2289
2152
 
2290
- // Initialize all endpoints.
2291
- // Must be done after initializing static and default endpoints to support html embeddings.
2292
- for (const endpoint of this.endpoints.values()) {
2293
- await endpoint._initialize(this);
2294
- }
2295
- for (const endpoint of this.err_endpoints.values()) {
2296
- await endpoint._initialize(this);
2297
- }
2298
- /* @performance */ this.performance.end("init-endpoints");
2299
-
2300
2153
  // Initialize users.
2301
2154
  if (this.db) {
2302
- this.users._initialize();
2155
+ await this.users._initialize();
2303
2156
  /* @performance */ this.performance.end("init-users");
2304
2157
  }
2305
2158
 
2306
2159
  // Database preview endpoints (only when production mode is disabled).
2307
- if (this.db) {
2308
- this.db._initialize_db_preview();
2309
- /* @performance */ this.performance.end("init-db-preview");
2310
- }
2160
+ // if (this.db) {
2161
+ // this.db._initialize_db_preview();
2162
+ // /* @performance */ this.performance.end("init-db-preview");
2163
+ // }
2311
2164
 
2312
2165
  // Payments.
2313
2166
  if (this.payments !== undefined) {
@@ -2594,9 +2447,9 @@ export class Server {
2594
2447
  }
2595
2448
 
2596
2449
  // Start static file watcher.
2597
- if (!this.production) {
2598
- this.static_file_watcher.start();
2599
- }
2450
+ // if (!this.production && this.file_watcher) {
2451
+ // this.static_file_watcher.start();
2452
+ // }
2600
2453
 
2601
2454
  // Start the rate limiting client/server, also when forking.
2602
2455
  if (this.db) {
@@ -2607,13 +2460,11 @@ export class Server {
2607
2460
  /* @performance */ this.performance.end("init-rate-limit");
2608
2461
  }
2609
2462
 
2610
- // Initialize, compile and bundle ts and js.
2611
- await this._init_ts();
2612
-
2613
2463
  // Production & Master.
2614
2464
  let forked = false;
2615
- if (this.production && this.multiprocessing && libcluster.isPrimary) {
2616
-
2465
+ if (this.production && this.multiprocessing && libcluster.isPrimary && this.processes > 1) {
2466
+ this.log(0, `Starting ${this.processes} threads.`);
2467
+
2617
2468
  // Vars.
2618
2469
  let active_threads = 0;
2619
2470
  const thread_ids: Record<string, string> = {};
@@ -2683,6 +2534,12 @@ export class Server {
2683
2534
  } else {
2684
2535
  forked = this.production && this.multiprocessing;
2685
2536
 
2537
+ // Load worker class modules.
2538
+ // if (libcluster.isWorker) {
2539
+ // const worker = new WorkerClass();
2540
+ // worker.start();
2541
+ // }
2542
+
2686
2543
  // Set default port.
2687
2544
  let http_port: number, https_port: number;
2688
2545
  if (this.port == null) {
@@ -2758,12 +2615,15 @@ export class Server {
2758
2615
  }
2759
2616
 
2760
2617
  // Start browser preview on primary node.
2761
- if (this.browser_preview && !forked) {
2762
- await this.browser_preview.start();
2763
- await this.browser_preview.navigate(this.full_domain);
2764
- }
2618
+ // if (this.browser_preview && !forked) {
2619
+ // await this.browser_preview.start();
2620
+ // await this.browser_preview.navigate(this.full_domain);
2621
+ // }
2765
2622
 
2766
- // /* @performance */ this.performance.dump();
2623
+ /* @performance */
2624
+ if (logger.log_level >= 2) {
2625
+ this.performance.dump();
2626
+ }
2767
2627
  }
2768
2628
 
2769
2629
  /* @docs:
@@ -2809,9 +2669,9 @@ export class Server {
2809
2669
  logger.log(0, log_source, "Stopping typescript watcher.");
2810
2670
  this._stop_tscompiler_watcher();
2811
2671
  }
2812
- if (this.static_file_watcher) {
2813
- this.static_file_watcher.stop();
2814
- }
2672
+ // if (this.static_file_watcher) {
2673
+ // this.static_file_watcher.stop();
2674
+ // }
2815
2675
 
2816
2676
  // Stop sockets.
2817
2677
  if (this.https) {
@@ -3061,21 +2921,22 @@ export class Server {
3061
2921
  */
3062
2922
  endpoint(...endpoints: (none | Endpoint | EndpointOptions | (none | EndpointOptions | Endpoint)[])[]): this {
3063
2923
  for (let i = 0; i < endpoints.length; i++) {
3064
- let init_endpoint = endpoints[i];
3065
2924
 
3066
2925
  // Skip.
3067
- if (init_endpoint == null) {
2926
+ if (endpoints[i] == null) {
3068
2927
  continue;
3069
2928
  }
3070
2929
 
3071
2930
  // Is array of endpoints.
3072
- if (Array.isArray(init_endpoint)) {
3073
- this.endpoint(...init_endpoint);
2931
+ if (Array.isArray(endpoints[i])) {
2932
+ this.endpoint(...endpoints[i] as any);
3074
2933
  continue;
3075
2934
  }
3076
2935
 
3077
2936
  // Initialize endpoint.
2937
+ let init_endpoint: Endpoint | ConstructorParameters<typeof Endpoint>[0] = endpoints[i] as any;
3078
2938
  if (!(init_endpoint instanceof Endpoint)) {
2939
+ (init_endpoint as any)._server = this;
3079
2940
  init_endpoint = new Endpoint(init_endpoint);
3080
2941
  }
3081
2942
  const endpoint = init_endpoint as Endpoint;
@@ -3095,7 +2956,7 @@ export class Server {
3095
2956
  if (endpoint._path && this.file_watcher?.add_exclude) {
3096
2957
  this.file_watcher!.add_exclude(endpoint._path);
3097
2958
  }
3098
- this.static_file_watcher.add(endpoint);
2959
+ // this.static_file_watcher.add(endpoint);
3099
2960
  }
3100
2961
  }
3101
2962
  return this;
@@ -3129,7 +2990,7 @@ export class Server {
3129
2990
  error_endpoint(status_code: number, endpoint: Endpoint | EndpointOptions): this {
3130
2991
  this.err_endpoints.set(
3131
2992
  status_code,
3132
- endpoint instanceof Endpoint ? endpoint : new Endpoint(endpoint)
2993
+ endpoint instanceof Endpoint ? endpoint : new Endpoint({...endpoint, _server: this}),
3133
2994
  );
3134
2995
  return this;
3135
2996
  }