@vandenberghinc/volt 1.1.5 → 1.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/backend/dist/cjs/database.d.ts +41 -68
- package/backend/dist/cjs/database.js +127 -76
- package/backend/dist/cjs/endpoint.d.ts +23 -9
- package/backend/dist/cjs/endpoint.js +98 -21
- package/backend/dist/cjs/frontend.d.ts +0 -2
- package/backend/dist/cjs/frontend.js +9 -9
- package/backend/dist/cjs/image_endpoint.d.ts +3 -1
- package/backend/dist/cjs/image_endpoint.js +2 -1
- package/backend/dist/cjs/payments/paddle.js +10 -2
- package/backend/dist/cjs/plugins/css.d.ts +6 -5
- package/backend/dist/cjs/plugins/css.js +32 -7
- package/backend/dist/cjs/plugins/ts/compiler.d.ts +6 -1
- package/backend/dist/cjs/plugins/ts/compiler.js +26 -2
- package/backend/dist/cjs/plugins/ts/preprocessing.js +5 -3
- package/backend/dist/cjs/server.d.ts +7 -13
- package/backend/dist/cjs/server.js +184 -303
- package/backend/dist/cjs/status.d.ts +1 -0
- package/backend/dist/cjs/status.js +2 -1
- package/backend/dist/cjs/stream.d.ts +5 -3
- package/backend/dist/cjs/stream.js +13 -4
- package/backend/dist/cjs/users.d.ts +1 -1
- package/backend/dist/cjs/users.js +87 -72
- package/backend/dist/cjs/utils.d.ts +17 -9
- package/backend/dist/cjs/utils.js +22 -64
- package/backend/dist/cjs/view.d.ts +2 -2
- package/backend/dist/cjs/view.js +38 -40
- package/backend/dist/cjs/volt.d.ts +3 -2
- package/backend/dist/cjs/volt.js +2 -2
- package/backend/dist/css/volt.css +5 -0
- package/backend/dist/esm/database.d.ts +41 -68
- package/backend/dist/esm/database.js +127 -76
- package/backend/dist/esm/endpoint.d.ts +23 -9
- package/backend/dist/esm/endpoint.js +99 -22
- package/backend/dist/esm/frontend.d.ts +0 -2
- package/backend/dist/esm/frontend.js +9 -9
- package/backend/dist/esm/image_endpoint.d.ts +3 -1
- package/backend/dist/esm/image_endpoint.js +2 -1
- package/backend/dist/esm/payments/paddle.js +11 -3
- package/backend/dist/esm/plugins/css.d.ts +6 -5
- package/backend/dist/esm/plugins/css.js +32 -6
- package/backend/dist/esm/plugins/ts/compiler.d.ts +6 -1
- package/backend/dist/esm/plugins/ts/compiler.js +26 -2
- package/backend/dist/esm/plugins/ts/preprocessing.js +5 -3
- package/backend/dist/esm/server.d.ts +7 -13
- package/backend/dist/esm/server.js +182 -301
- package/backend/dist/esm/status.d.ts +1 -0
- package/backend/dist/esm/status.js +1 -0
- package/backend/dist/esm/stream.d.ts +5 -3
- package/backend/dist/esm/stream.js +13 -4
- package/backend/dist/esm/users.d.ts +1 -1
- package/backend/dist/esm/users.js +87 -72
- package/backend/dist/esm/utils.d.ts +17 -9
- package/backend/dist/esm/utils.js +21 -62
- package/backend/dist/esm/view.d.ts +2 -2
- package/backend/dist/esm/view.js +38 -40
- package/backend/dist/esm/volt.d.ts +3 -2
- package/backend/dist/esm/volt.js +2 -1
- package/backend/dist/esm-dev/blacklist.js +1 -1
- package/backend/dist/esm-dev/cli.js +2 -2
- package/backend/dist/esm-dev/database.d.ts +41 -68
- package/backend/dist/esm-dev/database.js +128 -77
- package/backend/dist/esm-dev/endpoint.d.ts +23 -9
- package/backend/dist/esm-dev/endpoint.js +100 -23
- package/backend/dist/esm-dev/file_watcher.js +1 -1
- package/backend/dist/esm-dev/frontend.d.ts +0 -2
- package/backend/dist/esm-dev/frontend.js +9 -9
- package/backend/dist/esm-dev/image_endpoint.d.ts +3 -1
- package/backend/dist/esm-dev/image_endpoint.js +2 -1
- package/backend/dist/esm-dev/logger.js +1 -1
- package/backend/dist/esm-dev/payments/paddle.js +12 -4
- package/backend/dist/esm-dev/plugins/css.d.ts +6 -5
- package/backend/dist/esm-dev/plugins/css.js +33 -7
- package/backend/dist/esm-dev/plugins/ts/compiler.d.ts +6 -1
- package/backend/dist/esm-dev/plugins/ts/compiler.js +27 -3
- package/backend/dist/esm-dev/plugins/ts/preprocessing.js +7 -5
- package/backend/dist/esm-dev/rate_limit.js +1 -1
- package/backend/dist/esm-dev/server.d.ts +7 -13
- package/backend/dist/esm-dev/server.js +184 -303
- package/backend/dist/esm-dev/status.d.ts +1 -0
- package/backend/dist/esm-dev/status.js +1 -0
- package/backend/dist/esm-dev/stream.d.ts +5 -3
- package/backend/dist/esm-dev/stream.js +13 -4
- package/backend/dist/esm-dev/users.d.ts +1 -1
- package/backend/dist/esm-dev/users.js +88 -73
- package/backend/dist/esm-dev/utils.d.ts +17 -9
- package/backend/dist/esm-dev/utils.js +22 -63
- package/backend/dist/esm-dev/view.d.ts +2 -2
- package/backend/dist/esm-dev/view.js +39 -41
- package/backend/dist/esm-dev/volt.d.ts +3 -2
- package/backend/dist/esm-dev/volt.js +2 -1
- package/backend/src/database.ts +163 -152
- package/backend/src/endpoint.ts +123 -31
- package/backend/src/frontend.ts +9 -8
- package/backend/src/image_endpoint.ts +4 -0
- package/backend/src/payments/paddle.ts +11 -3
- package/backend/src/plugins/css.ts +36 -8
- package/backend/src/plugins/ts/compiler.ts +37 -1
- package/backend/src/plugins/ts/preprocessing.ts +5 -3
- package/backend/src/server.ts +167 -306
- package/backend/src/status.ts +1 -0
- package/backend/src/stream.ts +28 -8
- package/backend/src/users.ts +87 -72
- package/backend/src/utils.ts +58 -25
- package/backend/src/view.ts +30 -28
- package/backend/src/{volt.js → volt.ts} +2 -1
- package/backend/tsconfig.cjs.json +3 -3
- package/backend/tsconfig.esm.json +3 -3
- package/frontend/dist/elements/base.d.ts +397 -415
- package/frontend/dist/elements/base.js +565 -328
- package/frontend/dist/elements/module.d.ts +26 -12
- package/frontend/dist/elements/module.js +69 -32
- package/frontend/dist/elements/register_element.d.ts +3 -0
- package/frontend/dist/elements/register_element.js +22 -0
- package/frontend/dist/modules/auth.d.ts +1 -0
- package/frontend/dist/modules/auth.js +6 -5
- package/frontend/dist/modules/color.d.ts +159 -0
- package/frontend/dist/modules/color.js +315 -0
- package/frontend/dist/modules/colors.d.ts +1 -26
- package/frontend/dist/modules/colors.js +417 -338
- package/frontend/dist/modules/cookies.d.ts +1 -0
- package/frontend/dist/modules/cookies.js +1 -0
- package/frontend/dist/modules/events.d.ts +1 -0
- package/frontend/dist/modules/events.js +1 -0
- package/frontend/dist/modules/google.d.ts +1 -0
- package/frontend/dist/modules/google.js +1 -0
- package/frontend/dist/modules/meta.d.ts +1 -0
- package/frontend/dist/modules/meta.js +1 -0
- package/frontend/dist/modules/mutex.d.ts +1 -2
- package/frontend/dist/modules/mutex.js +3 -4
- package/frontend/dist/modules/paddle.d.ts +1 -0
- package/frontend/dist/modules/paddle.js +14 -13
- package/frontend/dist/modules/scheme.d.ts +1 -0
- package/frontend/dist/modules/scheme.js +4 -2
- package/frontend/dist/modules/statics.d.ts +1 -0
- package/frontend/dist/modules/statics.js +1 -0
- package/frontend/dist/modules/support.d.ts +1 -0
- package/frontend/dist/modules/support.js +3 -2
- package/frontend/dist/modules/theme.d.ts +56 -0
- package/frontend/dist/{ui → modules}/theme.js +186 -75
- package/frontend/dist/modules/themes.d.ts +1 -1
- package/frontend/dist/modules/themes.js +1 -0
- package/frontend/dist/modules/user.d.ts +1 -0
- package/frontend/dist/modules/user.js +11 -10
- package/frontend/dist/modules/utils.d.ts +23 -2
- package/frontend/dist/modules/utils.js +93 -1
- package/frontend/dist/types/gradient.js +4 -0
- package/frontend/dist/ui/border_button.d.ts +0 -25
- package/frontend/dist/ui/border_button.js +50 -51
- package/frontend/dist/ui/button.d.ts +0 -21
- package/frontend/dist/ui/button.js +41 -46
- package/frontend/dist/ui/canvas.js +15 -15
- package/frontend/dist/ui/checkbox.d.ts +3 -17
- package/frontend/dist/ui/checkbox.js +36 -30
- package/frontend/dist/ui/code.d.ts +15 -82
- package/frontend/dist/ui/code.js +150 -125
- package/frontend/dist/ui/color.d.ts +0 -1
- package/frontend/dist/ui/color.js +1 -1
- package/frontend/dist/ui/context_menu.d.ts +4 -2
- package/frontend/dist/ui/context_menu.js +16 -17
- package/frontend/dist/ui/css.js +2 -0
- package/frontend/dist/ui/divider.d.ts +0 -7
- package/frontend/dist/ui/divider.js +21 -25
- package/frontend/dist/ui/dropdown.d.ts +13 -7
- package/frontend/dist/ui/dropdown.js +65 -30
- package/frontend/dist/ui/for_each.d.ts +0 -5
- package/frontend/dist/ui/for_each.js +17 -22
- package/frontend/dist/ui/form.d.ts +17 -12
- package/frontend/dist/ui/form.js +21 -18
- package/frontend/dist/ui/frame_modes.d.ts +9 -12
- package/frontend/dist/ui/frame_modes.js +8 -10
- package/frontend/dist/ui/google_map.d.ts +0 -11
- package/frontend/dist/ui/google_map.js +23 -28
- package/frontend/dist/ui/gradient.d.ts +0 -5
- package/frontend/dist/ui/gradient.js +17 -22
- package/frontend/dist/ui/image.d.ts +27 -58
- package/frontend/dist/ui/image.js +99 -93
- package/frontend/dist/ui/input.d.ts +20 -97
- package/frontend/dist/ui/input.js +192 -170
- package/frontend/dist/ui/link.d.ts +0 -18
- package/frontend/dist/ui/link.js +42 -48
- package/frontend/dist/ui/list.js +36 -37
- package/frontend/dist/ui/loader_button.d.ts +4 -19
- package/frontend/dist/ui/loader_button.js +35 -37
- package/frontend/dist/ui/loaders.d.ts +0 -8
- package/frontend/dist/ui/loaders.js +20 -25
- package/frontend/dist/ui/popup.d.ts +11 -8
- package/frontend/dist/ui/popup.js +183 -24
- package/frontend/dist/ui/pseudo.d.ts +3 -3
- package/frontend/dist/ui/pseudo.js +14 -17
- package/frontend/dist/ui/scroller.d.ts +10 -48
- package/frontend/dist/ui/scroller.js +306 -300
- package/frontend/dist/ui/slider.d.ts +9 -3
- package/frontend/dist/ui/slider.js +31 -17
- package/frontend/dist/ui/spacer.d.ts +0 -9
- package/frontend/dist/ui/spacer.js +21 -26
- package/frontend/dist/ui/span.js +13 -15
- package/frontend/dist/ui/stack.d.ts +14 -75
- package/frontend/dist/ui/stack.js +166 -169
- package/frontend/dist/ui/steps.d.ts +10 -23
- package/frontend/dist/ui/steps.js +47 -34
- package/frontend/dist/ui/style.d.ts +4 -3
- package/frontend/dist/ui/style.js +13 -18
- package/frontend/dist/ui/switch.d.ts +10 -4
- package/frontend/dist/ui/switch.js +24 -16
- package/frontend/dist/ui/table.d.ts +0 -23
- package/frontend/dist/ui/table.js +113 -119
- package/frontend/dist/ui/tabs.d.ts +3 -19
- package/frontend/dist/ui/tabs.js +35 -29
- package/frontend/dist/ui/text.d.ts +0 -8
- package/frontend/dist/ui/text.js +20 -25
- package/frontend/dist/ui/title.d.ts +0 -15
- package/frontend/dist/ui/title.js +39 -45
- package/frontend/dist/ui/ui.d.ts +0 -2
- package/frontend/dist/ui/ui.js +0 -2
- package/frontend/dist/ui/view.d.ts +3 -17
- package/frontend/dist/ui/view.js +27 -32
- package/frontend/dist/volt.d.ts +2 -1
- package/frontend/dist/volt.js +3 -1
- package/frontend/examples/dashboard/dashboard.ts +774 -0
- package/frontend/examples/theme/theme.ts +58 -0
- package/frontend/src/css/volt.css +5 -0
- package/frontend/src/elements/base.ts +767 -545
- package/frontend/src/elements/module.ts +90 -29
- package/frontend/src/elements/register_element.ts +24 -0
- package/frontend/src/modules/auth.ts +7 -6
- package/frontend/src/modules/color.ts +348 -0
- package/frontend/src/modules/colors.ts +468 -449
- package/frontend/src/modules/cookies.ts +1 -0
- package/frontend/src/modules/events.ts +1 -0
- package/frontend/src/modules/google.ts +1 -0
- package/frontend/src/modules/meta.ts +2 -1
- package/frontend/src/modules/mutex.ts +2 -4
- package/frontend/src/modules/paddle.ts +21 -20
- package/frontend/src/modules/scheme.ts +4 -3
- package/frontend/src/modules/statics.ts +2 -1
- package/frontend/src/modules/support.ts +3 -2
- package/frontend/src/modules/theme.ts +413 -0
- package/frontend/src/modules/themes.ts +2 -1
- package/frontend/src/modules/user.ts +12 -11
- package/frontend/src/modules/utils.ts +125 -2
- package/frontend/src/ui/border_button.ts +41 -37
- package/frontend/src/ui/button.ts +33 -32
- package/frontend/src/ui/canvas.ts +5 -2
- package/frontend/src/ui/checkbox.ts +21 -22
- package/frontend/src/ui/code.ts +92 -86
- package/frontend/src/ui/context_menu.ts +7 -5
- package/frontend/src/ui/css.ts +1 -1
- package/frontend/src/ui/divider.ts +15 -10
- package/frontend/src/ui/dropdown.ts +38 -21
- package/frontend/src/ui/for_each.ts +9 -8
- package/frontend/src/ui/form.ts +26 -21
- package/frontend/src/ui/frame_modes.ts +13 -17
- package/frontend/src/ui/google_map.ts +15 -13
- package/frontend/src/ui/gradient.ts +9 -8
- package/frontend/src/ui/image.ts +108 -86
- package/frontend/src/ui/input.ts +145 -144
- package/frontend/src/ui/link.ts +25 -23
- package/frontend/src/ui/list.ts +12 -6
- package/frontend/src/ui/loader_button.ts +26 -25
- package/frontend/src/ui/loaders.ts +12 -11
- package/frontend/src/ui/popup.ts +168 -14
- package/frontend/src/ui/pseudo.ts +5 -3
- package/frontend/src/ui/scroller.ts +303 -294
- package/frontend/src/ui/slider.ts +15 -10
- package/frontend/src/ui/spacer.ts +14 -11
- package/frontend/src/ui/span.ts +6 -2
- package/frontend/src/ui/stack.ts +196 -183
- package/frontend/src/ui/steps.ts +38 -22
- package/frontend/src/ui/style.ts +7 -4
- package/frontend/src/ui/switch.ts +16 -11
- package/frontend/src/ui/table.ts +42 -34
- package/frontend/src/ui/tabs.ts +20 -19
- package/frontend/src/ui/text.ts +12 -11
- package/frontend/src/ui/title.ts +22 -20
- package/frontend/src/ui/ui.ts +0 -2
- package/frontend/src/ui/view.ts +20 -19
- package/frontend/src/volt.ts +3 -1
- package/frontend/{compile.js → tools/compile.old.js} +2 -2
- package/frontend/tools/embed_scripts.js +69 -0
- package/frontend/tsconfig.json +26 -0
- package/package.json +8 -8
- package/frontend/dist/ui/theme.d.ts +0 -25
- package/frontend/exports.json +0 -1340
- package/frontend/src/modules/date.js +0 -535
- package/frontend/src/ui/color.ts +0 -117
- package/frontend/src/ui/theme.ts +0 -279
- /package/backend/src/{vinc.dev.js → vinc.dev.ts} +0 -0
|
@@ -13,8 +13,8 @@ import libcluster from 'cluster';
|
|
|
13
13
|
import * as os from 'os';
|
|
14
14
|
// ---------------------------------------------------------
|
|
15
15
|
// Imports.
|
|
16
|
-
import { vlib } from "
|
|
17
|
-
import { vhighlight } from "
|
|
16
|
+
import { vlib } from "@vinc";
|
|
17
|
+
import { vhighlight } from "@vinc";
|
|
18
18
|
import { Utils } from "./utils.js";
|
|
19
19
|
import { Meta } from './meta.js';
|
|
20
20
|
import * as Mail from './plugins/mail.js';
|
|
@@ -23,14 +23,12 @@ import { Endpoint } from "./endpoint.js";
|
|
|
23
23
|
import { ImageEndpoint } from "./image_endpoint.js";
|
|
24
24
|
import { Stream } from "./stream.js";
|
|
25
25
|
import { Database } from "./database.js";
|
|
26
|
-
import { StaticFileWatcher
|
|
26
|
+
import { /*StaticFileWatcher,*/ FileWatcher } from "./file_watcher.js";
|
|
27
27
|
import { Users } from "./users.js";
|
|
28
28
|
import { Paddle } from "./payments/paddle.js";
|
|
29
29
|
import { RateLimits, RateLimitServer, RateLimitClient } from "./rate_limit.js";
|
|
30
30
|
import logger, { LogSource } from "./logger.js";
|
|
31
|
-
import
|
|
32
|
-
import * as TSPreprocessing from "./plugins/ts/preprocessing.js";
|
|
33
|
-
import { BrowserPreview } from "./plugins/browser.js";
|
|
31
|
+
// import { BrowserPreview } from "./plugins/browser.js";
|
|
34
32
|
const log_source = new LogSource("Server");
|
|
35
33
|
import { fileURLToPath } from 'url';
|
|
36
34
|
import { dirname } from 'path';
|
|
@@ -57,6 +55,10 @@ thread_monitor.start();
|
|
|
57
55
|
@description: Whether the server is in production more, or in development mode.
|
|
58
56
|
@type: boolean
|
|
59
57
|
@required: true
|
|
58
|
+
@parameter:
|
|
59
|
+
@name: localhost
|
|
60
|
+
@description: Wether to run on localhost. This overrides the given `ip` parameter, and makes the `ip` parameter optional.
|
|
61
|
+
@type: boolean
|
|
60
62
|
@parameter:
|
|
61
63
|
@name: ip
|
|
62
64
|
@description: The ip where the server will run on.
|
|
@@ -512,6 +514,7 @@ export class Server {
|
|
|
512
514
|
[".jpeg", "image/jpeg"],
|
|
513
515
|
[".jpg", "image/jpeg"],
|
|
514
516
|
[".js", "application/javascript"],
|
|
517
|
+
[".ts", "application/javascript"],
|
|
515
518
|
[".atom", "application/atom+xml"],
|
|
516
519
|
[".rss", "application/rss+xml"],
|
|
517
520
|
[".mml", "text/mathml"],
|
|
@@ -594,7 +597,7 @@ export class Server {
|
|
|
594
597
|
[".ra", "audio/x-realaudio"],
|
|
595
598
|
[".3gpp", "video/3gpp"],
|
|
596
599
|
[".3gp", "video/3gpp"],
|
|
597
|
-
[".ts", "video/mp2t"],
|
|
600
|
+
// [".ts", "video/mp2t"],
|
|
598
601
|
[".mp4", "video/mp4"],
|
|
599
602
|
[".mpeg", "video/mpeg"],
|
|
600
603
|
[".mpg", "video/mpeg"],
|
|
@@ -664,6 +667,7 @@ export class Server {
|
|
|
664
667
|
token_expiration;
|
|
665
668
|
google_tag;
|
|
666
669
|
production;
|
|
670
|
+
localhost;
|
|
667
671
|
multiprocessing;
|
|
668
672
|
processes;
|
|
669
673
|
company;
|
|
@@ -677,8 +681,9 @@ export class Server {
|
|
|
677
681
|
log_level;
|
|
678
682
|
tls;
|
|
679
683
|
file_watcher;
|
|
680
|
-
admin;
|
|
681
|
-
ts;
|
|
684
|
+
// public admin: AdminConfig;
|
|
685
|
+
// public ts: TypeScriptConfig;
|
|
686
|
+
lightweight;
|
|
682
687
|
performance;
|
|
683
688
|
csp;
|
|
684
689
|
default_headers;
|
|
@@ -697,8 +702,8 @@ export class Server {
|
|
|
697
702
|
keys;
|
|
698
703
|
_on_start;
|
|
699
704
|
_on_stop;
|
|
700
|
-
browser_preview;
|
|
701
|
-
static_file_watcher;
|
|
705
|
+
// public browser_preview?: BrowserPreview;
|
|
706
|
+
// public static_file_watcher: StaticFileWatcher;
|
|
702
707
|
is_file_watcher;
|
|
703
708
|
daemon;
|
|
704
709
|
_stop_tscompiler_watcher;
|
|
@@ -732,13 +737,17 @@ export class Server {
|
|
|
732
737
|
},
|
|
733
738
|
}, keys = [], payments = null, default_headers = null, google_tag = undefined, token_expiration = 86400, enable_2fa = false, enable_account_activation = true,
|
|
734
739
|
// honey_pot_key = null,
|
|
735
|
-
production = false, multiprocessing = true, processes = null, file_watcher =
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
},
|
|
740
|
+
production = false, localhost = true, multiprocessing = true, processes = null, file_watcher = false, offline = false, additional_sitemap_endpoints = [], log_level = 0, daemon = {},
|
|
741
|
+
// admin = {
|
|
742
|
+
// password: null,
|
|
743
|
+
// ips: [],
|
|
744
|
+
// },
|
|
745
|
+
// ts = {
|
|
746
|
+
// compiler_opts: {},
|
|
747
|
+
// output: undefined,
|
|
748
|
+
// },
|
|
749
|
+
// browser_preview = undefined,
|
|
750
|
+
lightweight = false, }) {
|
|
742
751
|
// @debug
|
|
743
752
|
// Async hook for tracking active processes during stop().
|
|
744
753
|
// const async_resource_map = new Map();
|
|
@@ -772,8 +781,8 @@ export class Server {
|
|
|
772
781
|
// this.async_hook.enable();
|
|
773
782
|
// Verify args.
|
|
774
783
|
vlib.Scheme.verify({ object: arguments[0], err_prefix: "Server: ", check_unknown: true, scheme: {
|
|
775
|
-
ip: "string",
|
|
776
|
-
port: "number",
|
|
784
|
+
ip: { type: "string", required: false },
|
|
785
|
+
port: { type: "number", required: false },
|
|
777
786
|
domain: "string",
|
|
778
787
|
statics: { type: "array", default: [] },
|
|
779
788
|
is_primary: { type: "boolean", default: true },
|
|
@@ -817,11 +826,8 @@ export class Server {
|
|
|
817
826
|
}
|
|
818
827
|
},
|
|
819
828
|
rate_limit: {
|
|
820
|
-
type: "object",
|
|
821
|
-
default:
|
|
822
|
-
ip: null,
|
|
823
|
-
port: RateLimitServer.default_port,
|
|
824
|
-
},
|
|
829
|
+
type: ["boolean", "object"],
|
|
830
|
+
default: false,
|
|
825
831
|
scheme: {
|
|
826
832
|
server: { type: "object", default: {}, scheme: {
|
|
827
833
|
ip: { type: "string", default: null },
|
|
@@ -861,6 +867,7 @@ export class Server {
|
|
|
861
867
|
enable_2fa: { type: "boolean", required: false },
|
|
862
868
|
enable_account_activation: { type: "boolean", required: false },
|
|
863
869
|
production: { type: "boolean", required: false },
|
|
870
|
+
localhost: { type: "boolean", required: false },
|
|
864
871
|
multiprocessing: { type: "boolean", required: false, default: true },
|
|
865
872
|
processes: { type: "number", required: false, default: null },
|
|
866
873
|
file_watcher: { type: ["null", "boolean", "object", FileWatcher], required: false },
|
|
@@ -868,22 +875,23 @@ export class Server {
|
|
|
868
875
|
additional_sitemap_endpoints: { type: "array", default: [] },
|
|
869
876
|
log_level: { type: "number", default: 0 },
|
|
870
877
|
daemon: { type: ["object", "boolean"], default: {} },
|
|
871
|
-
admin: {
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
ts: {
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
},
|
|
886
|
-
browser_preview: {
|
|
878
|
+
// admin: {type: "object", default: {}, attributes: {
|
|
879
|
+
// ips: {type: "array", default: []},
|
|
880
|
+
// password: {
|
|
881
|
+
// type: "string",
|
|
882
|
+
// verify: (param: string, attrs) => (param.length < 10 ? `Parameter "Server.admin.password" must have a length of at least 10 characters.` : undefined),
|
|
883
|
+
// },
|
|
884
|
+
// }},
|
|
885
|
+
// ts: {
|
|
886
|
+
// type: "object",
|
|
887
|
+
// required: false,
|
|
888
|
+
// scheme: {
|
|
889
|
+
// compiler_opts: {type: "object", default: {}},
|
|
890
|
+
// output: "string",
|
|
891
|
+
// },
|
|
892
|
+
// },
|
|
893
|
+
// browser_preview: {type: ["string", "undefined"], required: false, default: undefined},
|
|
894
|
+
lightweight: { type: "boolean", required: false },
|
|
887
895
|
} });
|
|
888
896
|
// Assign attributes directly.
|
|
889
897
|
this.port = port;
|
|
@@ -896,6 +904,8 @@ export class Server {
|
|
|
896
904
|
this.token_expiration = token_expiration;
|
|
897
905
|
this.google_tag = google_tag;
|
|
898
906
|
this.production = production;
|
|
907
|
+
this.localhost = localhost;
|
|
908
|
+
this.lightweight = lightweight;
|
|
899
909
|
this.multiprocessing = multiprocessing;
|
|
900
910
|
this.processes = processes == null ? os.cpus().length : processes;
|
|
901
911
|
this.company = company;
|
|
@@ -908,10 +918,15 @@ export class Server {
|
|
|
908
918
|
this.log_level = log_level;
|
|
909
919
|
this.tls = tls;
|
|
910
920
|
// this.file_watcher = file_watcher;
|
|
911
|
-
this.admin = admin;
|
|
912
|
-
this.ts = ts;
|
|
921
|
+
// this.admin = admin as AdminConfig;
|
|
922
|
+
// this.ts = ts as TypeScriptConfig;
|
|
913
923
|
this.endpoints = new Map();
|
|
914
924
|
this.err_endpoints = new Map();
|
|
925
|
+
// Assign based on localhost.
|
|
926
|
+
if (localhost) {
|
|
927
|
+
this.ip = "127.0.0.1";
|
|
928
|
+
this.domain = this.ip + ":" + (port + (this.tls ? 1 : 0));
|
|
929
|
+
}
|
|
915
930
|
/* @performance */ this.performance = new vlib.Performance("Server performance");
|
|
916
931
|
// Assign objects to server so it is easy to access.
|
|
917
932
|
this.status = Status;
|
|
@@ -1014,13 +1029,14 @@ export class Server {
|
|
|
1014
1029
|
this.endpoints = new Map();
|
|
1015
1030
|
this.err_endpoints = new Map();
|
|
1016
1031
|
// Browser preview.
|
|
1017
|
-
if (browser_preview) {
|
|
1018
|
-
|
|
1019
|
-
}
|
|
1032
|
+
// if (browser_preview) {
|
|
1033
|
+
// this.browser_preview = new BrowserPreview(browser_preview);
|
|
1034
|
+
// }
|
|
1020
1035
|
// Static file watcher.
|
|
1021
|
-
this.static_file_watcher = new StaticFileWatcher(this);
|
|
1036
|
+
// this.static_file_watcher = new StaticFileWatcher(this);
|
|
1022
1037
|
// Initialize file watcher.
|
|
1023
1038
|
if (file_watcher !== false) {
|
|
1039
|
+
console.warn("[Volt] Argument file_watcher is deprecated. This may be removed in future versions.");
|
|
1024
1040
|
if (file_watcher == null) {
|
|
1025
1041
|
// Null.
|
|
1026
1042
|
file_watcher = {};
|
|
@@ -1093,14 +1109,16 @@ export class Server {
|
|
|
1093
1109
|
this.smtp = nodemailer.createTransport(smtp);
|
|
1094
1110
|
}
|
|
1095
1111
|
// The rate limit server/client.
|
|
1096
|
-
if (
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
rate_limit.
|
|
1112
|
+
if (rate_limit) {
|
|
1113
|
+
if (this.is_primary) {
|
|
1114
|
+
this.rate_limit = new RateLimitServer({ ...(rate_limit.server ?? {}), _server: this });
|
|
1115
|
+
}
|
|
1116
|
+
else {
|
|
1117
|
+
if (rate_limit.server?.https) {
|
|
1118
|
+
rate_limit.client.https = true;
|
|
1119
|
+
}
|
|
1120
|
+
this.rate_limit = new RateLimitClient({ ...(rate_limit.client ?? {}), _server: this });
|
|
1102
1121
|
}
|
|
1103
|
-
this.rate_limit = new RateLimitClient({ ...(rate_limit.client ?? {}), _server: this });
|
|
1104
1122
|
}
|
|
1105
1123
|
// Blacklist class.
|
|
1106
1124
|
// if (this.honey_pot_key) {
|
|
@@ -1204,13 +1222,14 @@ export class Server {
|
|
|
1204
1222
|
if (favicon.exists() === false) {
|
|
1205
1223
|
throw Error(`Specified favicon path "${favicon}" does not exist.`);
|
|
1206
1224
|
}
|
|
1207
|
-
this.endpoint(
|
|
1225
|
+
this.endpoint({
|
|
1208
1226
|
method: "GET",
|
|
1209
1227
|
endpoint: "/favicon.ico",
|
|
1210
1228
|
data: favicon.load_sync({ type: "buffer" }),
|
|
1211
1229
|
content_type: this.get_content_type(favicon.extension()),
|
|
1212
1230
|
_is_static: true,
|
|
1213
|
-
|
|
1231
|
+
_server: this,
|
|
1232
|
+
});
|
|
1214
1233
|
// additional_file_watcher_paths.push(favicon.str());
|
|
1215
1234
|
}
|
|
1216
1235
|
// Create status endpoint.
|
|
@@ -1227,13 +1246,14 @@ export class Server {
|
|
|
1227
1246
|
else {
|
|
1228
1247
|
status_key = status_key_path.load_sync();
|
|
1229
1248
|
}
|
|
1230
|
-
this.endpoint(
|
|
1249
|
+
this.endpoint({
|
|
1231
1250
|
method: "GET",
|
|
1232
1251
|
endpoint: "/.status",
|
|
1233
1252
|
content_type: "application/json",
|
|
1234
1253
|
params: {
|
|
1235
1254
|
key: "string",
|
|
1236
1255
|
},
|
|
1256
|
+
_server: this,
|
|
1237
1257
|
callback: async (stream, params) => {
|
|
1238
1258
|
// Check key.
|
|
1239
1259
|
if (params.key !== status_key) {
|
|
@@ -1268,7 +1288,7 @@ export class Server {
|
|
|
1268
1288
|
data: status,
|
|
1269
1289
|
});
|
|
1270
1290
|
},
|
|
1271
|
-
})
|
|
1291
|
+
});
|
|
1272
1292
|
// Default static endpoints.
|
|
1273
1293
|
const defaults = [
|
|
1274
1294
|
{
|
|
@@ -1298,6 +1318,7 @@ export class Server {
|
|
|
1298
1318
|
compress: item.compress,
|
|
1299
1319
|
_path: item.path.str(),
|
|
1300
1320
|
_templates: item.templates,
|
|
1321
|
+
_server: this,
|
|
1301
1322
|
})
|
|
1302
1323
|
._load_data_by_path(this));
|
|
1303
1324
|
});
|
|
@@ -1306,6 +1327,11 @@ export class Server {
|
|
|
1306
1327
|
}
|
|
1307
1328
|
// Create the sitemap endpoint.
|
|
1308
1329
|
_create_sitemap() {
|
|
1330
|
+
// Logs.
|
|
1331
|
+
if (this.lightweight) {
|
|
1332
|
+
return;
|
|
1333
|
+
}
|
|
1334
|
+
logger.log(2, log_source, "Creating sitemap.");
|
|
1309
1335
|
let sitemap = "";
|
|
1310
1336
|
sitemap += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
|
|
1311
1337
|
sitemap += "<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n";
|
|
@@ -1321,16 +1347,22 @@ export class Server {
|
|
|
1321
1347
|
sitemap += `<url>\n <loc>${this.full_domain}/${endpoint}</loc>\n</url>\n`;
|
|
1322
1348
|
});
|
|
1323
1349
|
sitemap += "</urlset>\n";
|
|
1324
|
-
this.endpoint(
|
|
1350
|
+
this.endpoint({
|
|
1325
1351
|
method: "GET",
|
|
1326
1352
|
endpoint: "/sitemap.xml",
|
|
1327
1353
|
data: sitemap,
|
|
1328
1354
|
content_type: "application/xml",
|
|
1329
1355
|
compress: false,
|
|
1330
|
-
})
|
|
1356
|
+
});
|
|
1331
1357
|
}
|
|
1332
1358
|
// Create the robots.txt endpoint.
|
|
1333
1359
|
_create_robots_txt() {
|
|
1360
|
+
// Logs.
|
|
1361
|
+
if (this.lightweight) {
|
|
1362
|
+
return;
|
|
1363
|
+
}
|
|
1364
|
+
logger.log(2, log_source, "Creating robots.txt.");
|
|
1365
|
+
// Proceed.
|
|
1334
1366
|
let robots = "User-agent: *\n";
|
|
1335
1367
|
let disallowed = 0;
|
|
1336
1368
|
for (const endpoint of this.endpoints.values()) {
|
|
@@ -1343,36 +1375,44 @@ export class Server {
|
|
|
1343
1375
|
robots += `Disallow: \n`;
|
|
1344
1376
|
}
|
|
1345
1377
|
robots += `\nSitemap: ${this.full_domain}/sitemap.xml`;
|
|
1346
|
-
this.endpoint(
|
|
1378
|
+
this.endpoint({
|
|
1347
1379
|
method: "GET",
|
|
1348
1380
|
endpoint: "/robots.txt",
|
|
1349
1381
|
content_type: "text/plain",
|
|
1350
1382
|
data: robots,
|
|
1351
1383
|
compress: false,
|
|
1352
|
-
})
|
|
1384
|
+
});
|
|
1353
1385
|
}
|
|
1354
1386
|
// Create admin endpoint.
|
|
1355
|
-
|
|
1387
|
+
// @deprecated use MongoDB Atlas instead!
|
|
1388
|
+
/* private _create_admin_endpoint(): void {
|
|
1389
|
+
|
|
1390
|
+
// Logs.
|
|
1391
|
+
if (this.lightweight) { return; }
|
|
1392
|
+
logger.log(2, log_source, "Creating admin endpoint.");
|
|
1393
|
+
|
|
1356
1394
|
// Add admin tokens.
|
|
1357
1395
|
this.admin.tokens = [];
|
|
1396
|
+
|
|
1358
1397
|
// Verify token.
|
|
1359
|
-
const verify_token = (token) => {
|
|
1398
|
+
const verify_token = (token: string): boolean => {
|
|
1360
1399
|
const now = Date.now();
|
|
1361
|
-
let new_tokens = [];
|
|
1400
|
+
let new_tokens: Array<{token: string, expiration: number}> = [];
|
|
1362
1401
|
let verified = false;
|
|
1363
|
-
this.admin.tokens
|
|
1402
|
+
this.admin.tokens!.forEach((i) => {
|
|
1364
1403
|
if (now < i.expiration) {
|
|
1365
1404
|
if (i.token === token) {
|
|
1366
1405
|
verified = true;
|
|
1367
1406
|
}
|
|
1368
1407
|
new_tokens.push(i);
|
|
1369
1408
|
}
|
|
1370
|
-
})
|
|
1409
|
+
})
|
|
1371
1410
|
this.admin.tokens = new_tokens;
|
|
1372
1411
|
return verified;
|
|
1373
|
-
}
|
|
1412
|
+
}
|
|
1413
|
+
|
|
1374
1414
|
// Admin data.
|
|
1375
|
-
this.endpoint(
|
|
1415
|
+
this.endpoint({
|
|
1376
1416
|
method: "POST",
|
|
1377
1417
|
endpoint: "/admin/auth",
|
|
1378
1418
|
content_type: "application/json",
|
|
@@ -1385,31 +1425,34 @@ export class Server {
|
|
|
1385
1425
|
password: "string",
|
|
1386
1426
|
},
|
|
1387
1427
|
ip_whitelist: this.admin.ips,
|
|
1388
|
-
callback: async (stream, params) => {
|
|
1428
|
+
callback: async (stream: any, params: {password: string}) => {
|
|
1389
1429
|
// Check key.
|
|
1390
1430
|
if (params.password !== this.admin.password) {
|
|
1391
1431
|
return stream.send({
|
|
1392
1432
|
status: 403,
|
|
1393
|
-
headers: {
|
|
1433
|
+
headers: {"Content-Type": "text/plain"},
|
|
1394
1434
|
data: "Access Denied",
|
|
1395
|
-
})
|
|
1435
|
+
})
|
|
1396
1436
|
}
|
|
1437
|
+
|
|
1397
1438
|
// Generate token.
|
|
1398
1439
|
const token = {
|
|
1399
1440
|
token: String.random(32),
|
|
1400
1441
|
expiration: Date.now() + 3600 * 1000,
|
|
1401
1442
|
};
|
|
1402
|
-
this.admin.tokens
|
|
1443
|
+
this.admin.tokens!.push(token)
|
|
1444
|
+
|
|
1403
1445
|
// Response.
|
|
1404
1446
|
return stream.send({
|
|
1405
1447
|
status: 200,
|
|
1406
|
-
headers: {
|
|
1448
|
+
headers: {"Content-Type": "application/json"},
|
|
1407
1449
|
data: token,
|
|
1408
|
-
})
|
|
1450
|
+
})
|
|
1409
1451
|
},
|
|
1410
|
-
})
|
|
1452
|
+
})
|
|
1453
|
+
|
|
1411
1454
|
// Admin data.
|
|
1412
|
-
this.endpoint(
|
|
1455
|
+
this.endpoint({
|
|
1413
1456
|
method: "GET",
|
|
1414
1457
|
endpoint: "/admin/data",
|
|
1415
1458
|
content_type: "application/json",
|
|
@@ -1418,20 +1461,23 @@ export class Server {
|
|
|
1418
1461
|
token: "string",
|
|
1419
1462
|
},
|
|
1420
1463
|
ip_whitelist: this.admin.ips,
|
|
1421
|
-
callback: async (stream, params) => {
|
|
1464
|
+
callback: async (stream: any, params: {token: string}) => {
|
|
1422
1465
|
// Verify token.
|
|
1423
1466
|
if (!verify_token(params.token)) {
|
|
1424
1467
|
return stream.send({
|
|
1425
1468
|
status: 403,
|
|
1426
|
-
headers: {
|
|
1469
|
+
headers: {"Content-Type": "text/plain"},
|
|
1427
1470
|
data: "Access Denied",
|
|
1428
|
-
})
|
|
1471
|
+
})
|
|
1429
1472
|
}
|
|
1473
|
+
|
|
1430
1474
|
// Data.
|
|
1431
|
-
const data = {};
|
|
1475
|
+
const data: Record<string, any> = {};
|
|
1476
|
+
|
|
1432
1477
|
// Parse subscriptions.
|
|
1433
1478
|
const subscriptions = await this.payments._get_all_active_subscriptions();
|
|
1434
1479
|
data.subscriptions = subscriptions.length;
|
|
1480
|
+
|
|
1435
1481
|
// Load data.
|
|
1436
1482
|
const status = await this._sys_db.load("status", {
|
|
1437
1483
|
default: {
|
|
@@ -1441,22 +1487,26 @@ export class Server {
|
|
|
1441
1487
|
}
|
|
1442
1488
|
});
|
|
1443
1489
|
Object.assign(data, status);
|
|
1490
|
+
|
|
1444
1491
|
// System data.
|
|
1445
1492
|
data.cpu_usage = vlib.System.cpu_usage();
|
|
1446
1493
|
data.memory_usage = vlib.System.memory_usage();
|
|
1447
1494
|
data.network_usage = await vlib.System.network_usage();
|
|
1495
|
+
|
|
1448
1496
|
// Users.
|
|
1449
1497
|
data.users = (await this.users.list()).length;
|
|
1498
|
+
|
|
1450
1499
|
// Response.
|
|
1451
1500
|
return stream.send({
|
|
1452
1501
|
status: 200,
|
|
1453
|
-
headers: {
|
|
1502
|
+
headers: {"Content-Type": "application/json"},
|
|
1454
1503
|
data: data,
|
|
1455
|
-
})
|
|
1504
|
+
})
|
|
1456
1505
|
},
|
|
1457
|
-
})
|
|
1506
|
+
})
|
|
1507
|
+
|
|
1458
1508
|
// Admin view.
|
|
1459
|
-
this.endpoint(
|
|
1509
|
+
this.endpoint({
|
|
1460
1510
|
method: "GET",
|
|
1461
1511
|
endpoint: "/admin",
|
|
1462
1512
|
content_type: "application/json",
|
|
@@ -1480,14 +1530,17 @@ export class Server {
|
|
|
1480
1530
|
sub_fg: "#9099B4",
|
|
1481
1531
|
border: "#D6D6D6",
|
|
1482
1532
|
tint: "#64B878", //"#8EB8EB", //"#4E9CF7",
|
|
1483
|
-
}
|
|
1533
|
+
}
|
|
1534
|
+
|
|
1484
1535
|
// ... rest of the admin view implementation remains the same as it's client-side JavaScript ...
|
|
1485
1536
|
},
|
|
1486
1537
|
},
|
|
1487
|
-
})
|
|
1488
|
-
}
|
|
1538
|
+
})
|
|
1539
|
+
} */
|
|
1489
1540
|
// Initialize statics.
|
|
1490
1541
|
async _initialize_statics() {
|
|
1542
|
+
// Logs.
|
|
1543
|
+
logger.log(2, log_source, "Initializing static directories.");
|
|
1491
1544
|
// Static paths for the file watcher.
|
|
1492
1545
|
const static_paths = [];
|
|
1493
1546
|
// Add static file.
|
|
@@ -1507,6 +1560,7 @@ export class Server {
|
|
|
1507
1560
|
cache,
|
|
1508
1561
|
rate_limit: "global",
|
|
1509
1562
|
_is_static: true,
|
|
1563
|
+
_server: this,
|
|
1510
1564
|
});
|
|
1511
1565
|
const aspect_ratio = await e.get_aspect_ratio();
|
|
1512
1566
|
if (aspect_ratio != null) {
|
|
@@ -1526,6 +1580,7 @@ export class Server {
|
|
|
1526
1580
|
rate_limit: "global",
|
|
1527
1581
|
_path: path.str(),
|
|
1528
1582
|
_is_static: true,
|
|
1583
|
+
_server: this,
|
|
1529
1584
|
})
|
|
1530
1585
|
._load_data_by_path(this));
|
|
1531
1586
|
}
|
|
@@ -1629,177 +1684,13 @@ export class Server {
|
|
|
1629
1684
|
// Response.
|
|
1630
1685
|
return static_paths;
|
|
1631
1686
|
}
|
|
1632
|
-
// @todo this one is not TS
|
|
1633
|
-
// Initialize, compile & bundle js & ts.
|
|
1634
|
-
async _init_ts() {
|
|
1635
|
-
// Create dir.
|
|
1636
|
-
// Use ts.output instead of a /tmp/ dir since the node_modules for example is not present here.
|
|
1637
|
-
const tmp_volt_ts = new vlib.Path(this.ts.output ?? "/tmp/ts-dummy/").abs();
|
|
1638
|
-
if (this.ts.output && !tmp_volt_ts.exists()) {
|
|
1639
|
-
tmp_volt_ts.mkdir_sync();
|
|
1640
|
-
}
|
|
1641
|
-
// Gather all entry paths.
|
|
1642
|
-
const server = this;
|
|
1643
|
-
let has_ts = false;
|
|
1644
|
-
const volt_frontend = new vlib.Path(`${__dirname}/../../../frontend/dist/`).abs().str();
|
|
1645
|
-
const input_paths = [
|
|
1646
|
-
volt_frontend + "/volt.js",
|
|
1647
|
-
];
|
|
1648
|
-
const entries = {};
|
|
1649
|
-
for (const endpoint of this.endpoints.values()) {
|
|
1650
|
-
if (endpoint.view?.is_js_ts_view) {
|
|
1651
|
-
input_paths.push(endpoint.view.source_path.str());
|
|
1652
|
-
let output_path = tmp_volt_ts.join(endpoint.view.source_path).abs();
|
|
1653
|
-
const extension = output_path.extension();
|
|
1654
|
-
if (!has_ts && /.tsx?/.test(extension)) {
|
|
1655
|
-
has_ts = true;
|
|
1656
|
-
}
|
|
1657
|
-
const output = output_path.str().slice(0, -extension.length) + ".js";
|
|
1658
|
-
if (entries[output] === undefined) {
|
|
1659
|
-
entries[output] = {
|
|
1660
|
-
endpoints: [endpoint],
|
|
1661
|
-
path: output,
|
|
1662
|
-
extension,
|
|
1663
|
-
async bundle() {
|
|
1664
|
-
server.rate_limit?.reset_all(); // reset api limits.
|
|
1665
|
-
let bundle = undefined;
|
|
1666
|
-
let had_bundle = this.endpoints[0]?.view?.bundle != null;
|
|
1667
|
-
for (let e = 0; e < this.endpoints.length; e++) {
|
|
1668
|
-
if (bundle === undefined) {
|
|
1669
|
-
bundle = await this.endpoints[e]?.view?._bundle_ts(this.path);
|
|
1670
|
-
}
|
|
1671
|
-
else {
|
|
1672
|
-
await this.endpoints[e]?.view?._bundle_ts(this.path, bundle);
|
|
1673
|
-
}
|
|
1674
|
-
if (had_bundle && server.browser_preview) {
|
|
1675
|
-
await server.browser_preview.refresh(this.endpoints[e].endpoint);
|
|
1676
|
-
}
|
|
1677
|
-
}
|
|
1678
|
-
},
|
|
1679
|
-
};
|
|
1680
|
-
}
|
|
1681
|
-
else {
|
|
1682
|
-
entries[output].endpoints.push(endpoint);
|
|
1683
|
-
}
|
|
1684
|
-
}
|
|
1685
|
-
}
|
|
1686
|
-
const entry_values = Object.values(entries);
|
|
1687
|
-
if (has_ts && this.ts.output == null) {
|
|
1688
|
-
throw new Error(`Due to detected typescript endpoint source files the output path attribute "Server.ts.output" must be defined.`);
|
|
1689
|
-
}
|
|
1690
|
-
// For production just compile & bundle.
|
|
1691
|
-
if (this.is_file_watcher || this.production) {
|
|
1692
|
-
await TSCompiler.compile({
|
|
1693
|
-
entry_paths: input_paths,
|
|
1694
|
-
output: tmp_volt_ts.str(),
|
|
1695
|
-
preprocess: TSPreprocessing.volt_auto_imports,
|
|
1696
|
-
compiler_opts: {
|
|
1697
|
-
target: "ES2021",
|
|
1698
|
-
module: "esnext",
|
|
1699
|
-
moduleResolution: "node",
|
|
1700
|
-
lib: ["ES2021", "DOM"],
|
|
1701
|
-
declaration: false,
|
|
1702
|
-
strict: true,
|
|
1703
|
-
esModuleInterop: true,
|
|
1704
|
-
allowJs: true,
|
|
1705
|
-
checkJs: false,
|
|
1706
|
-
noImplicitAny: false,
|
|
1707
|
-
skipLibCheck: true,
|
|
1708
|
-
types: [],
|
|
1709
|
-
...this.ts.compiler_opts,
|
|
1710
|
-
rootDir: "/", // @warning is required to reliably match input and output file paths.
|
|
1711
|
-
},
|
|
1712
|
-
});
|
|
1713
|
-
let excluded = new Set();
|
|
1714
|
-
for (let i = 0; i < entry_values.length; i++) {
|
|
1715
|
-
await entry_values[i].bundle();
|
|
1716
|
-
// Add file watcher excludes.
|
|
1717
|
-
if (this.is_file_watcher) {
|
|
1718
|
-
for (const endpoint of entry_values[i].endpoints) {
|
|
1719
|
-
// console.log(entry_values[i].path, endpoint.view.bundle.inputs)
|
|
1720
|
-
for (let path of endpoint.view?.bundle?.inputs ?? []) {
|
|
1721
|
-
const vpath = new vlib.Path(path).abs();
|
|
1722
|
-
const ext = vpath.extension();
|
|
1723
|
-
path = vpath.str();
|
|
1724
|
-
if (path.startsWith(tmp_volt_ts.str())) {
|
|
1725
|
-
const js_path = path.slice(tmp_volt_ts.str().length);
|
|
1726
|
-
const ts_path = path.slice(tmp_volt_ts.str().length, -ext.length) + ".ts";
|
|
1727
|
-
if (new vlib.Path(js_path).exists() && !excluded.has(js_path)) {
|
|
1728
|
-
// console.log("Exclude", js_path)
|
|
1729
|
-
excluded.add(js_path);
|
|
1730
|
-
this.file_watcher.add_exclude(js_path);
|
|
1731
|
-
}
|
|
1732
|
-
if (new vlib.Path(ts_path).exists() && !excluded.has(ts_path)) {
|
|
1733
|
-
// console.log("Exclude", ts_path)
|
|
1734
|
-
excluded.add(ts_path);
|
|
1735
|
-
this.file_watcher.add_exclude(ts_path);
|
|
1736
|
-
}
|
|
1737
|
-
}
|
|
1738
|
-
}
|
|
1739
|
-
// process.exit(1)
|
|
1740
|
-
}
|
|
1741
|
-
}
|
|
1742
|
-
}
|
|
1743
|
-
}
|
|
1744
|
-
// Development.
|
|
1745
|
-
else {
|
|
1746
|
-
// Compile with watcher enabled.
|
|
1747
|
-
const res = await TSCompiler.compile({
|
|
1748
|
-
entry_paths: input_paths,
|
|
1749
|
-
output: tmp_volt_ts.str(),
|
|
1750
|
-
preprocess: TSPreprocessing.volt_auto_imports,
|
|
1751
|
-
error_limit: 10,
|
|
1752
|
-
compiler_opts: {
|
|
1753
|
-
target: "ES2021",
|
|
1754
|
-
module: "esnext",
|
|
1755
|
-
moduleResolution: "node",
|
|
1756
|
-
lib: ["ES2021", "DOM"],
|
|
1757
|
-
declaration: false,
|
|
1758
|
-
strict: true,
|
|
1759
|
-
esModuleInterop: true,
|
|
1760
|
-
allowJs: true,
|
|
1761
|
-
checkJs: false,
|
|
1762
|
-
noImplicitAny: false,
|
|
1763
|
-
skipLibCheck: true,
|
|
1764
|
-
types: [],
|
|
1765
|
-
...this.ts.compiler_opts,
|
|
1766
|
-
rootDir: "/", // @warning is required to reliably match input and output file paths.
|
|
1767
|
-
},
|
|
1768
|
-
watch: {
|
|
1769
|
-
enabled: true,
|
|
1770
|
-
log_level: 0,
|
|
1771
|
-
on_change: async (file_name) => {
|
|
1772
|
-
// console.log("File", file_name, "has changed.")
|
|
1773
|
-
logger.log(2, log_source, `Typescript output file ${file_name} has changed.`);
|
|
1774
|
-
// Check if the file path is part of an endpoint.
|
|
1775
|
-
const entry = entries[file_name];
|
|
1776
|
-
if (entry != null) {
|
|
1777
|
-
await entry.bundle();
|
|
1778
|
-
}
|
|
1779
|
-
// Check every other entries inputs' to see if that entry should be rebundled as well.
|
|
1780
|
-
for (let i = 0; i < entry_values.length; i++) {
|
|
1781
|
-
const entry = entry_values[i];
|
|
1782
|
-
if (entry.path !== file_name && entry.endpoints.iterate(e => e.view?.bundle?.inputs?.includes(file_name) ? true : undefined)) {
|
|
1783
|
-
await entry.bundle();
|
|
1784
|
-
}
|
|
1785
|
-
}
|
|
1786
|
-
},
|
|
1787
|
-
},
|
|
1788
|
-
});
|
|
1789
|
-
if (res.errors.length > 0) {
|
|
1790
|
-
res.debug();
|
|
1791
|
-
}
|
|
1792
|
-
for (let i = 0; i < entry_values.length; i++) {
|
|
1793
|
-
await entry_values[i].bundle();
|
|
1794
|
-
}
|
|
1795
|
-
this._stop_tscompiler_watcher = res.stop;
|
|
1796
|
-
}
|
|
1797
|
-
}
|
|
1798
1687
|
// ---------------------------------------------------------
|
|
1799
1688
|
// Server (private).
|
|
1800
1689
|
// Initialize.
|
|
1801
1690
|
// Initialize.
|
|
1802
1691
|
async initialize() {
|
|
1692
|
+
// Logs.
|
|
1693
|
+
logger.log(1, log_source, "Initializing server.");
|
|
1803
1694
|
/* @performance */ this.performance.start();
|
|
1804
1695
|
// File watcher.
|
|
1805
1696
|
if (this.is_file_watcher) {
|
|
@@ -1808,9 +1699,9 @@ export class Server {
|
|
|
1808
1699
|
// Create default endpoints for excluded static file watch paths.
|
|
1809
1700
|
this._create_default_endpoints();
|
|
1810
1701
|
// Exclude the typescript output directory from the file watcher.
|
|
1811
|
-
if (this.ts.output) {
|
|
1812
|
-
|
|
1813
|
-
}
|
|
1702
|
+
// if (this.ts.output) {
|
|
1703
|
+
// this.file_watcher!.add_exclude(this.ts.output);
|
|
1704
|
+
// }
|
|
1814
1705
|
// Add the volt backend source files to the additional files.
|
|
1815
1706
|
this.file_watcher.add_path(__dirname);
|
|
1816
1707
|
this.file_watcher.add_exclude(`${__dirname}/frontend_globals.js`);
|
|
@@ -1827,15 +1718,6 @@ export class Server {
|
|
|
1827
1718
|
this.file_watcher.add_exclude(item.path);
|
|
1828
1719
|
}
|
|
1829
1720
|
});
|
|
1830
|
-
// Initialize all endpoints since this is required for _init_ts()
|
|
1831
|
-
for (const endpoint of this.endpoints.values()) {
|
|
1832
|
-
await endpoint._initialize(this);
|
|
1833
|
-
}
|
|
1834
|
-
for (const endpoint of this.err_endpoints.values()) {
|
|
1835
|
-
await endpoint._initialize(this);
|
|
1836
|
-
}
|
|
1837
|
-
// Add typescript/js view endpoint excludes.
|
|
1838
|
-
await this._init_ts();
|
|
1839
1721
|
if (!this.production) {
|
|
1840
1722
|
[
|
|
1841
1723
|
`${process.env.PERSISTANCE}/private/dev/vinc/vlib/js/vlib.js`,
|
|
@@ -1896,9 +1778,9 @@ export class Server {
|
|
|
1896
1778
|
if (this.db) {
|
|
1897
1779
|
await this.db.initialize();
|
|
1898
1780
|
// Database collections.
|
|
1899
|
-
this._sys_db = this.db.create_collection("_sys"); // the volt sys collection.
|
|
1781
|
+
this._sys_db = await this.db.create_collection("_sys"); // the volt sys collection.
|
|
1900
1782
|
// Accessible collections.
|
|
1901
|
-
this.storage = this.db.create_collection("_storage"); // the sys backend storage collection for the user's server.
|
|
1783
|
+
this.storage = await this.db.create_collection("_storage"); // the sys backend storage collection for the user's server.
|
|
1902
1784
|
/* @performance */ this.performance.end("init-db");
|
|
1903
1785
|
// Load keys.
|
|
1904
1786
|
const keys_document = await this._sys_db.load("keys");
|
|
@@ -1965,30 +1847,21 @@ export class Server {
|
|
|
1965
1847
|
this._create_default_endpoints();
|
|
1966
1848
|
/* @performance */ this.performance.end("create-default-endpoints");
|
|
1967
1849
|
// Create admin endpoints.
|
|
1968
|
-
this._create_admin_endpoint();
|
|
1969
|
-
/* @performance */ this.performance.end("create-admin-endpoints");
|
|
1850
|
+
// this._create_admin_endpoint();
|
|
1851
|
+
// /* @performance */ this.performance.end("create-admin-endpoints");
|
|
1970
1852
|
// Create static endpoints.
|
|
1971
1853
|
await this._initialize_statics();
|
|
1972
1854
|
/* @performance */ this.performance.end("create-static-endpoints");
|
|
1973
|
-
// Initialize all endpoints.
|
|
1974
|
-
// Must be done after initializing static and default endpoints to support html embeddings.
|
|
1975
|
-
for (const endpoint of this.endpoints.values()) {
|
|
1976
|
-
await endpoint._initialize(this);
|
|
1977
|
-
}
|
|
1978
|
-
for (const endpoint of this.err_endpoints.values()) {
|
|
1979
|
-
await endpoint._initialize(this);
|
|
1980
|
-
}
|
|
1981
|
-
/* @performance */ this.performance.end("init-endpoints");
|
|
1982
1855
|
// Initialize users.
|
|
1983
1856
|
if (this.db) {
|
|
1984
|
-
this.users._initialize();
|
|
1857
|
+
await this.users._initialize();
|
|
1985
1858
|
/* @performance */ this.performance.end("init-users");
|
|
1986
1859
|
}
|
|
1987
1860
|
// Database preview endpoints (only when production mode is disabled).
|
|
1988
|
-
if (this.db) {
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
}
|
|
1861
|
+
// if (this.db) {
|
|
1862
|
+
// this.db._initialize_db_preview();
|
|
1863
|
+
// /* @performance */ this.performance.end("init-db-preview");
|
|
1864
|
+
// }
|
|
1992
1865
|
// Payments.
|
|
1993
1866
|
if (this.payments !== undefined) {
|
|
1994
1867
|
await this.payments._initialize();
|
|
@@ -2242,9 +2115,9 @@ export class Server {
|
|
|
2242
2115
|
return;
|
|
2243
2116
|
}
|
|
2244
2117
|
// Start static file watcher.
|
|
2245
|
-
if (!this.production) {
|
|
2246
|
-
|
|
2247
|
-
}
|
|
2118
|
+
// if (!this.production && this.file_watcher) {
|
|
2119
|
+
// this.static_file_watcher.start();
|
|
2120
|
+
// }
|
|
2248
2121
|
// Start the rate limiting client/server, also when forking.
|
|
2249
2122
|
if (this.db) {
|
|
2250
2123
|
/* @performance */ this.performance.start();
|
|
@@ -2253,11 +2126,10 @@ export class Server {
|
|
|
2253
2126
|
}
|
|
2254
2127
|
/* @performance */ this.performance.end("init-rate-limit");
|
|
2255
2128
|
}
|
|
2256
|
-
// Initialize, compile and bundle ts and js.
|
|
2257
|
-
await this._init_ts();
|
|
2258
2129
|
// Production & Master.
|
|
2259
2130
|
let forked = false;
|
|
2260
|
-
if (this.production && this.multiprocessing && libcluster.isPrimary) {
|
|
2131
|
+
if (this.production && this.multiprocessing && libcluster.isPrimary && this.processes > 1) {
|
|
2132
|
+
this.log(0, `Starting ${this.processes} threads.`);
|
|
2261
2133
|
// Vars.
|
|
2262
2134
|
let active_threads = 0;
|
|
2263
2135
|
const thread_ids = {};
|
|
@@ -2316,6 +2188,11 @@ export class Server {
|
|
|
2316
2188
|
}
|
|
2317
2189
|
else {
|
|
2318
2190
|
forked = this.production && this.multiprocessing;
|
|
2191
|
+
// Load worker class modules.
|
|
2192
|
+
// if (libcluster.isWorker) {
|
|
2193
|
+
// const worker = new WorkerClass();
|
|
2194
|
+
// worker.start();
|
|
2195
|
+
// }
|
|
2319
2196
|
// Set default port.
|
|
2320
2197
|
let http_port, https_port;
|
|
2321
2198
|
if (this.port == null) {
|
|
@@ -2385,11 +2262,14 @@ export class Server {
|
|
|
2385
2262
|
}
|
|
2386
2263
|
}
|
|
2387
2264
|
// Start browser preview on primary node.
|
|
2388
|
-
if (this.browser_preview && !forked) {
|
|
2389
|
-
|
|
2390
|
-
|
|
2265
|
+
// if (this.browser_preview && !forked) {
|
|
2266
|
+
// await this.browser_preview.start();
|
|
2267
|
+
// await this.browser_preview.navigate(this.full_domain);
|
|
2268
|
+
// }
|
|
2269
|
+
/* @performance */
|
|
2270
|
+
if (logger.log_level >= 2) {
|
|
2271
|
+
this.performance.dump();
|
|
2391
2272
|
}
|
|
2392
|
-
// /* @performance */ this.performance.dump();
|
|
2393
2273
|
}
|
|
2394
2274
|
/* @docs:
|
|
2395
2275
|
* @title: On start
|
|
@@ -2430,9 +2310,9 @@ export class Server {
|
|
|
2430
2310
|
logger.log(0, log_source, "Stopping typescript watcher.");
|
|
2431
2311
|
this._stop_tscompiler_watcher();
|
|
2432
2312
|
}
|
|
2433
|
-
if (this.static_file_watcher) {
|
|
2434
|
-
|
|
2435
|
-
}
|
|
2313
|
+
// if (this.static_file_watcher) {
|
|
2314
|
+
// this.static_file_watcher.stop();
|
|
2315
|
+
// }
|
|
2436
2316
|
// Stop sockets.
|
|
2437
2317
|
if (this.https) {
|
|
2438
2318
|
await this.https.close();
|
|
@@ -2659,18 +2539,19 @@ export class Server {
|
|
|
2659
2539
|
*/
|
|
2660
2540
|
endpoint(...endpoints) {
|
|
2661
2541
|
for (let i = 0; i < endpoints.length; i++) {
|
|
2662
|
-
let init_endpoint = endpoints[i];
|
|
2663
2542
|
// Skip.
|
|
2664
|
-
if (
|
|
2543
|
+
if (endpoints[i] == null) {
|
|
2665
2544
|
continue;
|
|
2666
2545
|
}
|
|
2667
2546
|
// Is array of endpoints.
|
|
2668
|
-
if (Array.isArray(
|
|
2669
|
-
this.endpoint(...
|
|
2547
|
+
if (Array.isArray(endpoints[i])) {
|
|
2548
|
+
this.endpoint(...endpoints[i]);
|
|
2670
2549
|
continue;
|
|
2671
2550
|
}
|
|
2672
2551
|
// Initialize endpoint.
|
|
2552
|
+
let init_endpoint = endpoints[i];
|
|
2673
2553
|
if (!(init_endpoint instanceof Endpoint)) {
|
|
2554
|
+
init_endpoint._server = this;
|
|
2674
2555
|
init_endpoint = new Endpoint(init_endpoint);
|
|
2675
2556
|
}
|
|
2676
2557
|
const endpoint = init_endpoint;
|
|
@@ -2689,7 +2570,7 @@ export class Server {
|
|
|
2689
2570
|
if (endpoint._path && this.file_watcher?.add_exclude) {
|
|
2690
2571
|
this.file_watcher.add_exclude(endpoint._path);
|
|
2691
2572
|
}
|
|
2692
|
-
this.static_file_watcher.add(endpoint);
|
|
2573
|
+
// this.static_file_watcher.add(endpoint);
|
|
2693
2574
|
}
|
|
2694
2575
|
}
|
|
2695
2576
|
return this;
|
|
@@ -2720,7 +2601,7 @@ export class Server {
|
|
|
2720
2601
|
@type: Endpoint, object
|
|
2721
2602
|
*/
|
|
2722
2603
|
error_endpoint(status_code, endpoint) {
|
|
2723
|
-
this.err_endpoints.set(status_code, endpoint instanceof Endpoint ? endpoint : new Endpoint(endpoint));
|
|
2604
|
+
this.err_endpoints.set(status_code, endpoint instanceof Endpoint ? endpoint : new Endpoint({ ...endpoint, _server: this }));
|
|
2724
2605
|
return this;
|
|
2725
2606
|
}
|
|
2726
2607
|
// ---------------------------------------------------------
|